/* ==========================================
   1. 全体レイアウト
   ========================================== */
.history-container {
  padding: 20px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 80vh;
  overflow-x: hidden;
}

.history-title {
  font-family: serif;
  color: #5d4037;
  border-bottom: 2px dashed #5d4037;
  margin-bottom: 40px;
  text-align: center;
}

/* ==========================================
   2. 本の土台（スマホ・レスポンシブ完全対応）
   ========================================== */
.book-container {
  position: relative;
  /* 画面幅の半分（見開きで100%弱）に収まるサイズ感 */
  width: 45vw !important; 
  max-width: 300px !important;
  aspect-ratio: 3 / 4;
  perspective: 1500px;
  
  /* 閉じている時の位置：左側にめくるスペースを空ける */
  margin: 0 auto 0 35% !important; 
  transition: transform 0.5s ease-in-out;
}

/* PCサイズでの表示 */
@media (min-width: 768px) {
  .book-container {
    width: 400px !important;
    max-width: none !important;
    height: 530px !important;
    margin: 0 auto !important; 
    aspect-ratio: auto;
  }
}

.book {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}

/* ==========================================
   3. ページの設定
   ========================================== */
.page {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  transform-origin: left;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.645, 0.045, 0.355, 1);
}

.front, .back {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  backface-visibility: hidden;
  box-sizing: border-box;
  border: 1px solid #dcd3c1;
  box-shadow: inset 5px 0 10px rgba(0,0,0,0.05);
  overflow-y: auto;
  background: #fff;
  padding: 15px; /* スマホ用に余白を少し詰める */
}

.back {
  transform: rotateY(180deg);
  background: #f9f9f9;
}

.flipped {
  transform: rotateY(-180deg);
}

/* ==========================================
   4. コンテンツ装飾
   ========================================== */
.front p, .back p {
  font-family: 'Yomogi', cursive;
  line-height: 1.4;
  font-size: 0.75rem !important; /* スマホで文字がはみ出ないサイズ */
  word-break: break-all;
  margin: 0 0 10px 0;
}

/* 表紙と裏表紙 */
.cover .front, #p4 .back {
  background: #5d4037;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================
   5. 操作ボタン
   ========================================== */
.controls {
  margin-top: 50px; /* 本の下に十分なスペースを空ける */
  display: flex;
  gap: 15px;
  justify-content: center;
  width: 100%;
}

.controls button {
  padding: 10px 20px;
  border: 2px solid #5d4037;
  background: #fff;
  font-weight: bold;
  cursor: pointer;
}

/* ==========================================
   2. 本の土台（スマホ・レスポンシブ完全対応）
   ========================================== */
.book-container {
  position: relative;
  /* スマホでは画面幅の35%〜40%程度に抑える */
  width: 38vw !important; 
  max-width: 280px !important;
  aspect-ratio: 3 / 4;
  perspective: 1500px;
  
  /* 中央配置 */
  margin: 0 auto !important; 
  transition: transform 0.6s ease-in-out;
  /* はみ出しを考慮して少し余裕を持たせる */
  z-index: 10;
}

/* ★改善：開いた時に全体を少し縮小し、中央に留める */
.book-container.is-open {
  /* 0.8倍に縮小することで、見開きが左右にはみ出るのを防ぐ */
  transform: scale(0.85); 
}

/* PCサイズでの表示（PCは十分な幅があるので縮小不要） */
@media (min-width: 768px) {
  .book-container {
    width: 400px !important;
    max-width: none !important;
    height: 530px !important;
    margin: 40px auto !important; 
    aspect-ratio: auto;
  }
  .book-container.is-open {
    transform: scale(1); /* PCでは等倍 */
  }
}

/* ==========================================
   3. ページの設定
   ========================================== */
.page {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  /* 軸は左のままでOKですが、containerのscaleで制御します */
  transform-origin: left;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.645, 0.045, 0.355, 1);
}

/* コンテンツがはみ出さないよう文字サイズを再調整 */
.front p, .back p {
  font-family: 'Yomogi', cursive;
  line-height: 1.5;
  font-size: 0.7rem !important; /* さらに少し小さく */
  word-wrap: break-word;
  padding: 5px;
}

/* ==========================================
   4. コンテンツ装飾
   ========================================== */

/* ページ内の画像設定 */
.front img, .back img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 10px auto;
  border-radius: 4px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* テキストの調整 */
.front p, .back p {
  font-family: 'Yomogi', cursive;
  line-height: 1.5;
  /* スマホの画面幅に合わせて文字サイズを動的に変更 */
  font-size: clamp(0.6rem, 2.5vw, 0.8rem) !important;
  word-break: break-all;
  margin: 0 0 8px 0;
}

/* スマホ用のページ内余白調整 */
@media (max-width: 767px) {
  .front, .back {
    padding: 10px !important; /* 余白を削って表示面積を増やす */
  }
  
  /* 表紙などの大きな文字も調整 */
  .front h2, .back h2 {
    font-size: 0.9rem;
    margin-bottom: 5px;
  }
}

/* PCサイズでは読みやすいサイズに固定 */
@media (min-width: 768px) {
  .front p, .back p {
    font-size: 1rem !important;
  }
  .front, .back {
    padding: 30px !important;
  }
}