/* ============================================================
   DFN 学習サイト 共通スタイル
   ============================================================ */
:root {
  --ink: #1a2233;
  --ink-soft: #47536b;
  --ink-faint: #8a94a8;
  --bg: #fdfdfb;
  --bg-soft: #f4f5f2;
  --line: #dfe3ea;
  --accent: #0f62fe;        /* リンク・強調 */
  --accent-soft: #e8f0fe;
  --deriv: #8a5a00;         /* 導出ボックス */
  --deriv-bg: #fdf6e8;
  --assume: #0e6245;        /* 仮定ボックス */
  --assume-bg: #e9f6f0;
  --phys: #7a3e9d;          /* 物理的意味 */
  --phys-bg: #f6effb;
  --warn-bg: #fdecec;
  --warn: #b3261e;
  --code-bg: #12161f;
  --code-ink: #e6e9f0;
  --max-w: 900px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP",
               "Yu Gothic", Meiryo, system-ui, sans-serif;
  line-height: 1.9;
  -webkit-font-smoothing: antialiased;
}

/* ---------- ナビゲーション ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(253, 253, 251, 0.95);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.site-header .inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.site-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.site-nav {
  display: flex;
  gap: 0.15rem;
  flex-wrap: wrap;
}
.site-nav a {
  font-size: 0.82rem;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  white-space: nowrap;
}
.site-nav a:hover { background: var(--bg-soft); color: var(--ink); }
.site-nav a.current {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* ---------- 本文レイアウト ---------- */
main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 2rem 1.2rem 4rem;
}

h1 {
  font-size: 1.75rem;
  line-height: 1.4;
  border-bottom: 3px solid var(--accent);
  padding-bottom: 0.4rem;
  margin: 1rem 0 0.5rem;
}
h1 .phase-tag {
  display: block;
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.05em;
}
h2 {
  font-size: 1.35rem;
  margin: 3rem 0 1rem;
  padding: 0.3rem 0 0.3rem 0.7rem;
  border-left: 5px solid var(--accent);
  background: linear-gradient(90deg, var(--bg-soft), transparent);
}
h3 {
  font-size: 1.12rem;
  margin: 2.2rem 0 0.8rem;
  padding-bottom: 0.2rem;
  border-bottom: 1px dashed var(--line);
}
h4 { font-size: 1rem; margin: 1.6rem 0 0.6rem; }

p { margin: 0.9rem 0; }
.lead { font-size: 1.02rem; color: var(--ink-soft); }

a { color: var(--accent); }

ul, ol { padding-left: 1.6em; }
li { margin: 0.3rem 0; }

strong { color: var(--ink); }

/* ---------- 表 ---------- */
table {
  border-collapse: collapse;
  margin: 1.2rem 0;
  font-size: 0.9rem;
  width: 100%;
}
.table-wrap { overflow-x: auto; }
th, td {
  border: 1px solid var(--line);
  padding: 0.4rem 0.7rem;
  text-align: left;
  vertical-align: top;
}
th { background: var(--bg-soft); font-weight: 600; white-space: nowrap; }
tbody tr:nth-child(even) { background: #fafbf9; }

/* ---------- ボックス類 ---------- */
.box {
  border-radius: 10px;
  padding: 1rem 1.2rem;
  margin: 1.4rem 0;
  border: 1px solid var(--line);
}
.box > .box-title {
  font-weight: 700;
  font-size: 0.92rem;
  margin: 0 0 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.box p:first-of-type { margin-top: 0.2rem; }
.box p:last-child { margin-bottom: 0.2rem; }

.box.assumption { background: var(--assume-bg); border-color: #bfe3d4; }
.box.assumption .box-title { color: var(--assume); }

.box.derivation { background: var(--deriv-bg); border-color: #ecd9ac; }
.box.derivation .box-title { color: var(--deriv); }

.box.physics { background: var(--phys-bg); border-color: #e0cdee; }
.box.physics .box-title { color: var(--phys); }

.box.warning { background: var(--warn-bg); border-color: #f0c4c1; }
.box.warning .box-title { color: var(--warn); }

.box.summary { background: var(--accent-soft); border-color: #c4d7fb; }
.box.summary .box-title { color: var(--accent); }

.box.check { background: var(--bg-soft); }
.box.check .box-title { color: var(--ink); }

/* 定義(記号の初出) */
.sym-def {
  background: var(--bg-soft);
  border-left: 4px solid var(--ink-faint);
  padding: 0.6rem 1rem;
  margin: 1rem 0;
  font-size: 0.92rem;
  border-radius: 0 8px 8px 0;
}

/* 導出ステップ:番号付きの行ごとの説明 */
.deriv-step {
  display: grid;
  grid-template-columns: 2.2rem 1fr;
  gap: 0.6rem;
  margin: 0.9rem 0;
  align-items: baseline;
}
.deriv-step .step-no {
  font-weight: 700;
  color: var(--deriv);
  font-size: 0.9rem;
  text-align: right;
}
.deriv-step .step-body p { margin: 0.3rem 0; }

/* 式番号付きの重要式 */
.eq-highlight {
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  margin: 1.4rem 0;
  background: #fff;
  overflow-x: auto;
}

/* 折りたたみ(補足) */
details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  margin: 1rem 0;
  background: #fff;
}
details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--ink-soft);
  font-size: 0.92rem;
}
details[open] summary { margin-bottom: 0.5rem; }

/* ---------- コード ---------- */
pre.code-python, pre.code-text {
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 1rem 1.2rem;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.55;
  tab-size: 4;
}
code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}
p code, li code, td code {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.05em 0.35em;
  font-size: 0.85em;
}

.runnable { margin: 1.4rem 0; }
.runnable .run-bar {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}
button.run-btn, button.copy-btn, button.demo-btn {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.4rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button.run-btn:hover, button.demo-btn:hover { filter: brightness(1.15); }
button.run-btn:disabled { opacity: 0.55; cursor: wait; }
button.copy-btn {
  background: #fff;
  color: var(--accent);
}
button.copy-btn:hover { background: var(--accent-soft); }
.run-status { font-size: 0.8rem; color: var(--ink-faint); }
pre.py-out {
  background: #f7f8f5;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  font-size: 0.8rem;
  overflow-x: auto;
  white-space: pre-wrap;
  display: none;
}
pre.py-out.has-content { display: block; }
pre.py-out.py-error { color: var(--warn); background: var(--warn-bg); }

/* ---------- インタラクティブ図 ---------- */
.demo {
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 1.6rem 0;
  background: #fff;
  overflow: hidden;
}
.demo .demo-title {
  background: var(--bg-soft);
  padding: 0.5rem 1rem;
  font-weight: 700;
  font-size: 0.92rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.demo .demo-title::before { content: "🎛"; }
.demo .demo-body { padding: 0.8rem 1rem 1rem; }
.demo .demo-note {
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin: 0.5rem 0 0.8rem;
}
.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.4rem 1.4rem;
  margin: 0.6rem 0 0.8rem;
}
.ctl {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0 0.6rem;
  font-size: 0.85rem;
}
.ctl label { color: var(--ink-soft); }
.ctl .ctl-val {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  white-space: nowrap;
}
.ctl input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--accent);
  margin: 0.1rem 0 0.4rem;
}
.ctl-row {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
  margin: 0.4rem 0;
  font-size: 0.85rem;
}
.plot {
  width: 100%;
  min-height: 320px;
}
.plot-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
@media (max-width: 760px) {
  .plot-pair { grid-template-columns: 1fr; }
}

/* ---------- 章間ナビ・フッタ ---------- */
.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
}
.page-nav a {
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.6rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink-soft);
  max-width: 48%;
}
.page-nav a:hover { border-color: var(--accent); color: var(--accent); }
.page-nav .nav-label {
  display: block;
  font-size: 0.72rem;
  color: var(--ink-faint);
}
footer {
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.78rem;
  padding: 1.5rem 1rem 2.5rem;
  border-top: 1px solid var(--line);
}

/* ---------- 目次 ---------- */
.toc {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.8rem 1.4rem;
  font-size: 0.88rem;
  margin: 1.4rem 0;
}
.toc .toc-title { font-weight: 700; margin-bottom: 0.3rem; }
.toc ol { margin: 0.2rem 0; }
.toc a { text-decoration: none; }
.toc a:hover { text-decoration: underline; }

/* index のフェーズカード */
.phase-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.9rem;
  margin: 1.5rem 0;
}
.phase-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  text-decoration: none;
  color: var(--ink);
  background: #fff;
  transition: border-color 0.15s, transform 0.15s;
  display: block;
}
.phase-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.phase-card .pc-phase {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.06em;
}
.phase-card .pc-title { font-weight: 700; margin: 0.15rem 0 0.35rem; }
.phase-card .pc-desc { font-size: 0.82rem; color: var(--ink-soft); line-height: 1.6; }

/* 理解度チェックの解答 */
.answer { margin-top: 0.5rem; }

/* MathJax 数式のはみ出し対策 */
mjx-container[display="true"] {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  padding: 2px 0;
}
