/* ===== リセット & ベース ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* iOS Safari のフォント自動拡大を抑制（ただし pinch-zoom は維持） */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

:root {
  --primary: #1a5276;
  --primary-light: #2980b9;
  --primary-dark: #154360;
  --accent: #e67e22;
  --accent-light: #f39c12;
  --bg: #f4f6f9;
  --sidebar-bg: #1a2a3a;
  --sidebar-text: #c8d8e8;
  --sidebar-hover: #2c3e50;
  --sidebar-active: #2980b9;
  --content-bg: #ffffff;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --border: #dce3ec;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --sidebar-width: 300px;
  --header-height: 60px;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Noto Sans JP', 'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  font-size: 15px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ===== ヘッダー ===== */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--primary-dark);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  gap: 16px;
}

.app-header .logo {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: white;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header .logo span {
  color: var(--accent-light);
}

.menu-toggle {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: background 0.2s;
}
.menu-toggle:hover { background: rgba(255,255,255,0.1); }
.menu-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: white;
  border-radius: 2px;
  transition: all 0.3s;
}

/* ===== レイアウト ===== */
.app-body {
  display: flex;
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
}

/* ===== サイドバー ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  overflow-y: auto;
  transition: transform 0.3s ease;
  z-index: 900;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

.sidebar.hidden { transform: translateX(-100%); }

.sidebar-header {
  padding: 20px 20px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,0.4);
  font-weight: 600;
}

.toc-list {
  list-style: none;
  padding: 8px 0;
}

.toc-item {
  display: flex;
  align-items: stretch;
}

.toc-btn {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 10px 20px;
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  text-align: left;
  font-size: 0.85rem;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}

.toc-btn:hover {
  background: var(--sidebar-hover);
  color: white;
}

.toc-btn.active {
  background: rgba(41, 128, 185, 0.2);
  color: white;
  border-left-color: var(--sidebar-active);
}

.toc-num {
  min-width: 24px;
  height: 24px;
  background: rgba(255,255,255,0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: rgba(255,255,255,0.7);
  flex-shrink: 0;
  margin-top: 1px;
}

.toc-btn.active .toc-num {
  background: var(--sidebar-active);
  color: white;
}

.toc-text { flex: 1; }
.toc-text .en { font-size: 0.72rem; color: rgba(255,255,255,0.4); display: block; margin-top: 2px; }

/* ===== メインコンテンツ ===== */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  transition: margin-left 0.3s ease;
  padding: 0;
}

.main-content.full { margin-left: 0; }

/* ===== ページ ===== */
.page {
  display: none;
  padding: 0 0 60px;
  animation: fadeIn 0.3s ease;
}

.page.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== ページヘッダー ===== */
.page-header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 60%, var(--primary-light) 100%);
  color: white;
  padding: 40px 48px 32px;
  position: relative;
  overflow: hidden;
}

.page-header::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 200px; height: 200px;
  background: rgba(255,255,255,0.05);
  border-radius: 50%;
}

.page-header::after {
  content: '';
  position: absolute;
  bottom: -60px; right: 60px;
  width: 150px; height: 150px;
  background: rgba(255,255,255,0.04);
  border-radius: 50%;
}

.chapter-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
  color: rgba(255,255,255,0.9);
}

.page-header h1 {
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 6px;
  position: relative;
}

.page-header .en-title {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.6);
  font-style: italic;
  position: relative;
}

/* ===== コンテンツ本文 ===== */
.page-body {
  max-width: 860px;
  margin: 0 auto;
  padding: 36px 48px;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* ===== 著者情報 ===== */
.author-info {
  background: #f0f4f8;
  border-left: 4px solid var(--primary-light);
  border-radius: 0 8px 8px 0;
  padding: 14px 18px;
  margin-bottom: 28px;
  font-size: 0.83rem;
  color: var(--text-light);
  line-height: 1.6;
}

/* ===== 見出し ===== */
.chapter-title {
  display: none; /* ページヘッダーで表示するので非表示 */
}

h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  margin: 32px 0 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
  line-height: 1.4;
}

h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin: 24px 0 10px;
  padding-left: 10px;
  border-left: 3px solid var(--accent);
  line-height: 1.4;
}

h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin: 18px 0 8px;
}

/* ===== 段落 ===== */
p {
  margin-bottom: 14px;
  line-height: 1.85;
}

/* ===== 水平線 ===== */
.section-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

/* ===== リスト ===== */
ul, ol {
  margin: 10px 0 14px 24px;
  line-height: 1.8;
}
li { margin-bottom: 4px; }
li strong { color: var(--primary-dark); }

/* ===== テーブル ===== */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 20px 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead { background: var(--primary); color: white; }
thead th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 0.85rem;
}

tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:nth-child(even) { background: #f8fafc; }
tbody tr:hover { background: #eef4fb; }

td {
  padding: 11px 16px;
  vertical-align: top;
  line-height: 1.6;
}

/* ===== 図 ===== */
.figure {
  margin: 24px 0;
  text-align: center;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.figure img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  display: block;
  margin: 0 auto;
}

/* 全画像が親要素からはみ出さないよう保証 */
img { max-width: 100%; height: auto; }

.figure-missing {
  color: var(--text-light);
  font-style: italic;
  padding: 30px;
}

/* ===== コード ===== */
code {
  background: #f0f4f8;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  color: #c0392b;
  font-family: 'Consolas', 'Monaco', monospace;
}

pre {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* ===== ナビゲーション ===== */
.page-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 48px;
  border-top: 1px solid var(--border);
  background: white;
  max-width: 860px;
  margin: 0 auto;
  gap: 12px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  transition: background 0.2s, transform 0.1s;
  text-decoration: none;
}

.nav-btn:hover { background: var(--primary-light); transform: translateY(-1px); }
.nav-btn:active { transform: translateY(0); }
.nav-btn.secondary { background: white; color: var(--primary); border: 2px solid var(--primary); }
.nav-btn.secondary:hover { background: var(--primary); color: white; }
.nav-btn:disabled { background: #bdc3c7; cursor: not-allowed; transform: none; }

.page-indicator {
  font-size: 0.85rem;
  color: var(--text-light);
  font-weight: 500;
}

/* ===== 進捗バー ===== */
.progress-bar {
  position: fixed;
  top: var(--header-height);
  left: 0; right: 0;
  height: 3px;
  background: rgba(255,255,255,0.1);
  z-index: 999;
}

.progress-fill {
  height: 100%;
  background: var(--accent-light);
  transition: width 0.3s ease;
}

/* ===== オーバーレイ ===== */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 850;
  backdrop-filter: blur(2px);
}
.overlay.show { display: block; }

/* ===== レスポンシブ ===== */
@media (max-width: 768px) {
  :root { --sidebar-width: 280px; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.show { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .page-header { padding: 28px 20px 20px; }
  .page-header h1 { font-size: 1.25rem; }
  .page-header .en-title { font-size: 0.82rem; }
  .page-body { padding: 20px 16px; }
  .page-nav { padding: 14px 16px; gap: 8px; }
  .nav-btn { padding: 9px 14px; font-size: 0.82rem; }
  .page-indicator { font-size: 0.8rem; }

  /* テーブルのフォントサイズ縮小 */
  table { font-size: 0.8rem; }
  thead th { padding: 10px 10px; font-size: 0.78rem; }
  td { padding: 9px 10px; }

  /* 2カラム・3カラムのインライングリッドをモバイルで1カラムに */
  div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* タブボタンの最小幅を縮小 */
  .tab-btn { min-width: 90px; font-size: 0.82rem; padding: 8px 8px; }

  /* はみ出し防止：横スクロールバーを出さない */
  body { overflow-x: hidden; }

  /* pre・コードブロックが画面外にはみ出さないよう */
  pre, code { font-size: 0.78rem; }
  pre { white-space: pre; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* 行間を少し詰めてモバイルで縦に読みやすく */
  p { line-height: 1.75; }

  /* スクロールトップボタン：ナビボタンに被らない位置に */
  .scroll-top { bottom: 72px; right: 14px; width: 40px; height: 40px; font-size: 1rem; }

  /* インラインの小さなフォントサイズが 12px 未満にならないよう底上げ */
  /* （0.82rem × 15px base = 12.3px なので許容範囲） */
  /* 極端に小さい箇所だけ底上げ */
  [style*="font-size:0.7rem"], [style*="font-size: 0.7rem"] { font-size: 0.82rem !important; }
  [style*="font-size:0.72rem"], [style*="font-size: 0.72rem"] { font-size: 0.82rem !important; }
  [style*="font-size:0.75rem"], [style*="font-size: 0.75rem"] { font-size: 0.82rem !important; }
  [style*="font-size:0.78rem"], [style*="font-size: 0.78rem"] { font-size: 0.82rem !important; }
}

@media (min-width: 769px) {
  .sidebar { transform: translateX(0); }
  .sidebar.hidden { transform: translateX(-100%); }
  .main-content.full { margin-left: 0; }
}

/* ===== スクロールトップ ===== */
.scroll-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 44px;
  height: 44px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: all 0.2s;
  opacity: 0;
  pointer-events: none;
  z-index: 800;
}
.scroll-top.show { opacity: 1; pointer-events: auto; }
.scroll-top:hover { background: var(--primary-light); transform: translateY(-2px); }

/* ===== 検索ハイライト ===== */
mark { background: #fff176; padding: 0 2px; border-radius: 2px; }

/* ===== 印刷 ===== */
@media print {
  .app-header, .sidebar, .page-nav, .scroll-top, .progress-bar { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .page { display: block !important; page-break-after: always; }
}

/* ===== 表紙（Cover Page） ===== */
.cover-page {
  min-height: calc(100vh - var(--header-height));
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top right, rgba(41, 128, 185, 0.1), transparent),
              radial-gradient(circle at bottom left, rgba(230, 126, 34, 0.05), transparent);
  padding: 40px 20px;
}

.cover-content {
  max-width: 800px;
  text-align: center;
  animation: fadeInDown 0.8s ease-out;
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.cover-title {
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 800;
  color: var(--primary-dark);
  margin-bottom: 24px;
  line-height: 1.2;
  letter-spacing: -0.5px;
}

.cover-description {
  font-size: 1.25rem;
  color: var(--text-light);
  margin-bottom: 48px;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.6;
}

.link-button-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 60px;
}

.hero-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  border-radius: 16px;
  text-decoration: none;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  text-align: left;
  position: relative;
  overflow: hidden;
}

.hero-btn.primary {
  background: white;
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0,0,0,0.05);
}

.hero-btn.secondary {
  background: white;
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0,0,0,0.05);
}

.hero-btn:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 40px rgba(0,0,0,0.1);
  border-color: var(--primary-light);
}

.btn-icon {
  font-size: 2rem;
  background: #f0f4f8;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  transition: background 0.3s;
}

.hero-btn:hover .btn-icon {
  background: var(--primary-light);
  color: white;
}

.btn-text {
  display: flex;
  flex-direction: column;
}

.main-label {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}

.sub-label {
  font-size: 0.8rem;
  color: var(--text-light);
}

.start-journey {
  margin-top: 20px;
}

.start-journey .nav-btn {
  padding: 14px 40px;
  font-size: 1.1rem;
  border-radius: 30px;
  box-shadow: 0 4px 15px rgba(26, 82, 118, 0.3);
}

/* レスポンシブ調整 */
@media (max-width: 600px) {
  .cover-title { font-size: 2rem; }
  .cover-description { font-size: 1rem; }
  .hero-btn { padding: 16px; }
}

/* ===== タブナビゲーション（Tabs Nav） ===== */
.tabs-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: #f0f4f8;
  padding: 6px;
  border-radius: 12px;
  margin-bottom: 24px;
  position: sticky;
  top: calc(var(--header-height) + 3px);
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs-nav::-webkit-scrollbar { display: none; }

.tab-btn {
  flex: 1 1 auto;
  min-width: 120px;
  padding: 9px 14px;
  border: none;
  background: transparent;
  color: var(--text-light);
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  background: rgba(255,255,255,0.5);
  color: var(--primary);
}

.tab-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* タブコンテンツ制御 */
.tab-content {
  position: relative;
  min-height: 200px;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.4s ease;
}

.tab-pane.active {
  display: block;
}

/* プレースホルダーの装飾 */
.placeholder-msg {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-light);
  background: #f9fbfd;
  border: 2px dashed var(--border);
  border-radius: 12px;
  margin: 20px 0;
}

.placeholder-msg i {
  display: block;
  font-size: 2.5rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

@media (max-width: 768px) {
  .tabs-nav {
    margin-left: -20px;
    margin-right: -20px;
    border-radius: 0;
    padding: 8px 16px;
  }
}
