/* ページ全体のレイアウト調整 */
.main-content-area {
  flex-direction: column;      /* ヘッダーとメインコンテンツを縦並びに */
  align-items: stretch;        /* 各セクションを横幅いっぱいに */
  justify-content: flex-start; /* 上から順に配置 */
  padding: clamp(1.5rem, 3vw, 2.75rem) 0;
  box-sizing: border-box;
}

.main-content-wrapper,
.reference-main,
.books-grid,
.book-item,
.book-content {
  max-width: 100%;
  box-sizing: border-box;
}

.main-content-wrapper {
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 3.5vw, 2.25rem);
  overflow-x: hidden;
}

/* --- ヘッダー / タイトル --- */
.reference-header {
  position: relative;
  background: linear-gradient(135deg, rgba(255, 248, 220, 0.92), rgba(255, 224, 150, 0.85));
  padding: clamp(1.75rem, 3.5vw, 2.75rem) clamp(1.25rem, 4vw, 2.75rem);
  text-align: center;
  margin-bottom: clamp(2rem, 5vw, 3rem);
  border-radius: 18px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.15), inset 0 2px 0 rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.55);
  overflow: hidden;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.reference-header::before {
  content: "";
  position: absolute;
  inset: -40% -30% auto auto;
  width: 65%;
  padding-bottom: 65%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.65) 0%, rgba(255, 255, 255, 0) 70%);
  transform: rotate(12deg);
  pointer-events: none;
  mix-blend-mode: screen;
}

.reference-header::after {
  content: "";
  position: absolute;
  inset: auto auto -55% -25%;
  width: 60%;
  padding-bottom: 60%;
  background: radial-gradient(circle, rgba(255, 199, 95, 0.45) 0%, rgba(255, 199, 95, 0) 70%);
  transform: rotate(-8deg);
  pointer-events: none;
}

.reference-title {
  position: relative;
  z-index: 1;
  color: #4a3200;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.reference-title h1 {
  margin: 0;
  font-size: 2.2rem;
}

.reference-title .subtitle {
  margin: 0.5rem 0 0 0;
  font-size: 1.1rem;
  color: rgba(74, 50, 0, 0.82);
  font-weight: 500;
}

/* --- メインコンテンツのラッパー --- */
.main-content-wrapper {
  display: flex; /* PC表示ではサイドメニューとグリッドを横並びにする */
  gap: 2rem;
  align-items: flex-start; /* 上端揃え */
}

/* ヘッダーとグリッドをまとめるラッパー */
.reference-main {
  flex: 3; /* メニューより広い幅を確保 */
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  gap: clamp(1.5rem, 3vw, 2.5rem);
}

/* --- サイドメニュー --- */
.reference-menu {
  flex: 0.4; /* グリッドの1/3の幅を確保 */
  background-color: #4a4a4a; /* 画像に近い濃いグレー */
  padding: 1.5rem;
  border-radius: 8px;
}

.reference-menu ul {
  list-style: none; /* デフォルトの黒点を削除 */
  padding: 0;
  margin: 0;
}

.reference-menu li {
  margin-bottom: 1rem;
  color: white;
  padding-left: 1.2rem;
  position: relative;
}

/* リストの黒点を疑似要素で作成 */
.reference-menu li::before {
  content: '●';
  color: white;
  position: absolute;
  left: 0;
  top: 0;
}

.reference-menu li:last-child {
  margin-bottom: 0;
}

.reference-menu a {
  color: #fff;
  text-decoration: none;
  font-size: 1.1rem;
}

.reference-menu a:hover {
  text-decoration: underline;
}

/* --- 参考書グリッド --- */
.books-grid {
  display: grid;
  /* PC表示を基本とし、デフォルトを3列にする */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.5rem;
  width: 100%;
}

/* --- 参考書アイテム --- */
.book-item {
  background: #f9f9f9;
  border: 1px solid #ddd;
  border-radius: 5px;
  padding: 1rem;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
}

.book-content {
  display: flex;
  gap: 1rem;
  flex: 1;
  width: 100%;
  min-width: 0;
}

.book-image {
  flex: 0 0 120px;
  height: 160px;
  background: #cccccc;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.book-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.book-info {
  flex: 1;
  min-width: 0;
}

.book-info h3 {
  margin-top: 0;
}

.book-info p {
  line-height: 1.6;
  word-break: break-word;
}

.detail-toggle {
  margin-top: 0.5rem;
  color: #0066cc;
  text-decoration: underline;
  align-self: flex-start;
  display: inline-block;
}

.detail-toggle:hover,
.detail-toggle:visited {
  color: #0066cc;
  text-decoration: underline;
}

.book-detail {
  display: none;
  margin-top: 1rem;
  width: 100%;
}

.book-detail h4 {
  margin: 0 0 0.5rem;
}

.book-detail p {
  margin: 0;
  line-height: 1.6;
  word-break: break-word;
}

.book-detail ul {
  list-style: none;
  margin: 0;
  padding-left: 0;
  line-height: 1.6;
}

.book-detail ul li::before {
  content: '・';
  margin-right: 0.25rem;
}

.book-detail.show {
  display: block;
}

.book-link {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  background: #f9d643; /* 画像に近い黄色 */
  text-align: center;
  padding: 0.75rem;
  font-weight: bold;
  border-radius: 5px;
  color: #333;
  text-decoration: none;
  display: block;
}

.book-link a {
  color: #333;
  text-decoration: none;
}

.section-title {
  font-size: 2rem;
  margin: 3rem auto 1rem;
  width: 100%;
  max-width: 620px;
}

.book-section {
  width: 100%;
  max-width: 620px;
  margin: 0 auto 2rem;
  background: #fff;
  border-radius: 8px;
  padding: 1rem 1.5rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.book-section h3 {
  margin-top: 0;
  margin-bottom: 1rem;
  border-bottom: 1px solid #eee;
  padding-bottom: 0.5rem;
}

.book-section ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.book-section li {
  margin-bottom: 0.75rem;
}

.book-section a {
  color: #0077cc;
  text-decoration: none;
  font-weight: 500;
}

.book-section a:hover {
  color: #005999;
  text-decoration: underline;
}

/* --- YouTuber推薦参考書スライダー --- */
.latest-reference-section {
  width: 100%;
  max-width: 760px;
  margin: 3rem auto 2rem;
  background: #fff;
  border-radius: 8px;
  padding: 2rem 1.75rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.latest-reference-title {
  margin: 0 0 1.5rem;
  font-size: 1.6rem;
  font-weight: 700;
  padding-left: 1rem;
  position: relative;
}

.latest-reference-title::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  border-radius: 3px;
  background: linear-gradient(180deg, #ffbb00, #ff7b00);
}

.latest-reference-list {
  --card-gap: 1.1rem;
  display: flex;
  gap: var(--card-gap);
  overflow-x: auto;
  padding: 0 0.5rem 0.75rem;
  margin: 0;
  scroll-snap-type: x proximity;
}

.latest-reference-list::-webkit-scrollbar {
  height: 8px;
}

.latest-reference-list::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 999px;
}

.latest-reference-list::-webkit-scrollbar-thumb {
  background: #c7c7c7;
  border-radius: 999px;
}

.reference-article-card {
  flex: 0 0 clamp(110px, calc((100% - 5 * var(--card-gap)) / 6), 150px);
  max-width: clamp(110px, calc((100% - 5 * var(--card-gap)) / 6), 150px);
  min-width: 110px;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  scroll-snap-align: start;
}

.reference-article-card:hover .reference-article-thumbnail {
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
  transform: translateY(-4px);
}

.reference-article-thumbnail {
  width: 100%;
  aspect-ratio: 2.6 / 4;
  background: #fff;
  border-radius: 6px;
  border: 1px solid #e5e5e5;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.reference-article-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.reference-article-title {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: #333;
  text-align: center;
}

@media (max-width: 768px) {
  .latest-reference-section {
    padding: 1.5rem 1.25rem;
    margin: 2.5rem auto 1.5rem;
  }

  .latest-reference-title {
    font-size: 1.4rem;
    margin-bottom: 1.25rem;
  }

  .latest-reference-list {
    --card-gap: 0.85rem;
    padding: 0 0.25rem 0.65rem;
  }

  .reference-article-card {
    flex: 0 0 calc((100% - 3 * var(--card-gap)) / 4);
    max-width: calc((100% - 3 * var(--card-gap)) / 4);
    min-width: 95px;
  }
}

@media (max-width: 480px) {
  .latest-reference-list {
    --card-gap: 0.75rem;
  }

  .reference-article-card {
    min-width: 90px;
  }
}

/* =============================================== */
/* レスポンシブ対応 (画面サイズが小さい場合の表示) */
/* =============================================== */

/* 画面幅が991px以下の場合 (タブレットなど) */
@media (max-width: 991px) {
  .books-grid {
    /* 参考書グリッドを2列にする */
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* 画面幅が768px以下の場合 (スマホなど) */
@media (max-width: 768px) {
  .main-content-wrapper {
    /* サイドメニューと参考書グリッドを縦並びにする */
    flex-direction: column;
    padding: 0 clamp(0.75rem, 4vw, 1.5rem);
    gap: clamp(1.5rem, 5vw, 2rem);
  }
  
  /* サイドメニューを非表示に */
  .reference-menu {
    display: none;
  }

  .reference-main {
    gap: clamp(1.5rem, 5vw, 2rem);
  }

  /* スマホでは画像を上、説明文を下に並べる */
  .book-content {
    flex-direction: column;
  }

  .book-image {
    flex: none;
    width: min(140px, 55vw);
    aspect-ratio: 3 / 4;
    height: auto;
    margin: 0 auto 0.5rem;
  }

  .book-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .book-info {
    margin-bottom: 0.25rem;
  }

  /* スマホでも参考書は2列表示 */
  .books-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: clamp(0.5rem, 3vw, 0.75rem); /* 横の間隔を詰めて画面に収める */
    row-gap: clamp(0.85rem, 4vw, 1.2rem);
  }

  .book-item {
    padding: clamp(0.75rem, 3.5vw, 1rem); /* 余白を少し減らして幅を調整 */
  }
}

@media (max-width: 560px) {
  .books-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .book-item {
    margin: 0;
  }
}