:root{
  --paper:#FAF7F2; --card:#FFFFFF; --ink:#20242A; --ink-soft:#4A5058; --muted:#8A857C;
  --line:#E8E2D8; --line-strong:#D6CFC2; --tint:#F9F1E3; --note:#F2F1ED;
  --theta:#3D6BE5; --theta-ink:#2B52C4; --theta-soft:#EAF0FE;
  --r:#2E9E6B; --r-ink:#1C7A50; --r-soft:#E7F5EE;
  --arc:#E07B2E; --arc-ink:#B8611C; --arc-soft:#FDF0E4;
  --hint-bg:#FFF9E6; --hint-border:#FFE08A; --hint-text:#997A00;
  --serif:"Noto Serif JP","Hiragino Mincho ProN","Yu Mincho",serif;
}
*{box-sizing:border-box}
body{
  margin:0; background:var(--paper); color:var(--ink);
  font-family:"Zen Kaku Gothic New",sans-serif; font-size:17px; line-height:1.95;
  -webkit-text-size-adjust:100%; overflow-x:hidden;
}

/* App Layout (Sidebar + Main) */
.app-container { display: flex; min-height: 100vh; }
.sidebar { width: 300px; background: #fff; border-right: 1px solid var(--line); padding: 30px 20px; position: fixed; height: 100vh; overflow-y: auto; }
.main-content { flex: 1; margin-left: 300px; padding: 40px; display: flex; justify-content: center; }
.page-wrapper { max-width: 760px; width: 100%; display: none; }
.page-wrapper.active { display: block; animation: fadeIn 0.3s ease; }

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

/* Typography & Headers */
.runhead{ display:flex; justify-content:space-between; align-items:baseline; font-size:.72rem; letter-spacing:.14em; color:var(--muted); padding-bottom:14px; border-bottom:1px solid var(--line); margin-bottom:30px; }
h2{ font-family:var(--serif); font-size:1.65rem; font-weight:600; line-height:1.55; margin:0 0 24px; color:var(--theta-ink); }
h3{ display:flex; align-items:center; gap:10px; font-size:1.1rem; font-weight:700; margin:30px 0 15px; color:var(--ink); border-bottom:1px solid var(--line); padding-bottom:8px; }
h3.badge-q::before{ content:"問"; display:inline-block; background:var(--ink); color:#fff; width:28px; height:28px; border-radius:4px; text-align:center; line-height:28px; font-size:0.9rem; }
h3.badge-ex::before{ content:"例"; display:inline-block; background:var(--arc); color:#fff; width:28px; height:28px; border-radius:4px; text-align:center; line-height:28px; font-size:0.9rem; }

.hitokoto{ background:var(--tint); border-radius:16px; padding:20px 24px; margin:0 0 30px; font-size:1.15rem; font-weight:700; }
figure{ margin:0 0 30px; background:var(--card); border:1px solid var(--line); border-radius:18px; padding:18px; box-shadow:0 1px 2px rgba(32,36,42,.04); position:relative; text-align:center; }

/* Callout Boxes */
.hint-box { background:var(--hint-bg); border:1px solid var(--hint-border); border-radius:12px; padding:15px 20px; margin-bottom:20px; font-size:0.95rem; color:var(--hint-text); }
.hint-box::before { content:"💡 ヒント / 考え方"; display:block; font-weight:bold; margin-bottom:5px; font-size:0.85rem; color:#B38F00; }

.think-box { background:#F0F4FF; border-left:4px solid var(--theta); border-radius:0 12px 12px 0; padding:15px 20px; margin-bottom:20px; font-size:0.95rem; color:var(--ink); }
.think-box::before { content:"🤔 なぜそうなる？ (Deep Dive)"; display:block; font-weight:bold; margin-bottom:8px; font-size:0.85rem; color:var(--theta-ink); }

.warning-box { background:#FFF3F3; border-left:4px solid #E53E3E; border-radius:0 12px 12px 0; padding:15px 20px; margin-bottom:20px; font-size:0.95rem; }
.warning-box::before { content:"⚠️ よくあるミス (Traps)"; display:block; font-weight:bold; margin-bottom:8px; font-size:0.85rem; color:#C53030; }

/* Math Steps & Answers */
.math-box { background:#fff; border:1px solid var(--line); border-radius:12px; padding:20px; margin-bottom:20px; box-shadow:0 2px 8px rgba(0,0,0,0.02); }
.math-step { margin-bottom:14px; display:flex; align-items:baseline; }
.math-step .label { width:150px; font-size:0.9rem; color:var(--muted); flex-shrink:0; }
.math-step .eq { font-size:1.1rem; flex-grow:1; }
.ans-box { display:inline-block; border:1.5px solid var(--ink); padding:2px 12px; border-radius:6px; font-weight:bold; margin-left:10px; background:var(--tint); }

/* Details / Summary */
details { background:#fff; border:1px solid var(--line-strong); border-radius:12px; margin-bottom:20px; overflow:hidden; }
summary { display:block; padding:14px 20px; background:var(--theta-soft); color:var(--theta-ink); font-weight:bold; cursor:pointer; text-align:center; transition:background 0.2s; outline:none; }
summary::-webkit-details-marker { display:none; }
summary:hover { background:#DDE6FD; }
details[open] summary { background:#fff; border-bottom:1px dashed var(--line); color:var(--ink); text-align:left; }
details[open] summary::before { content:"▼ 解答・解説"; }
details:not([open]) summary::before { content:"👇 解答を見る"; }
.math-content { padding:20px; }

/* Interactive Sliders */
.slider-container { padding:0 20px; width:100%; max-width:440px; margin:0 auto; }
.ctl { display:grid; grid-template-columns:auto 1fr auto; align-items:center; gap:12px; margin-bottom:10px; }
.ctl output { font-family:Georgia, serif; font-size:1rem; min-width:5em; text-align:right; }
input[type=range] { -webkit-appearance:none; width:100%; height:4px; border-radius:99px; background:var(--line-strong); outline:none; cursor:pointer; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance:none; width:18px; height:18px; border-radius:50%; background:#fff; border:2.5px solid currentColor; cursor:grab; }

/* Sidebar TOC */
.sidebar h1 { font-size:1.2rem; margin-top:0; font-family:var(--serif); color:var(--ink); border-bottom:2px solid var(--ink); padding-bottom:10px; }
.toc-category { font-size:0.75rem; text-transform:uppercase; letter-spacing:0.1em; color:var(--muted); margin:24px 0 8px 10px; font-weight:700; }
.toc-list { list-style:none; padding:0; margin:0; }
.toc-list li { margin-bottom:4px; }
.toc-list a { text-decoration:none; color:var(--ink-soft); font-size:0.9rem; display:block; padding:8px 12px; border-radius:8px; transition:0.2s; }
.toc-list a:hover { background:var(--tint); color:var(--ink); }
.toc-list a.active { background:var(--theta-soft); color:var(--theta-ink); font-weight:700; }

/* Bottom Page Nav */
.page-nav { display:flex; justify-content:space-between; margin-top:50px; padding-top:20px; border-top:1px solid var(--line); }
.page-nav button { padding:12px 24px; background:#fff; border:1px solid var(--line-strong); border-radius:99px; font-family:inherit; font-weight:700; cursor:pointer; transition:0.2s; color:var(--ink); }
.page-nav button:hover { background:var(--ink); color:#fff; border-color:var(--ink); }
.page-nav button:disabled { opacity:0.3; cursor:not-allowed; }

/* Menu Hub Cards (index pages) */
.hub-container { max-width:1000px; width:100%; margin:0 auto; padding:60px 20px; line-height:1.7; }
.hero { text-align:center; margin-bottom:50px; }
.hero h1 { font-family:var(--serif); font-size:2.4rem; font-weight:600; color:var(--ink); margin:0 0 15px; line-height:1.3; }
.hero p { font-size:1.05rem; color:var(--ink-soft); max-width:600px; margin:0 auto; }
.badge { display:inline-block; background:var(--theta); color:#fff; padding:4px 12px; border-radius:99px; font-size:0.8rem; font-weight:bold; letter-spacing:0.1em; margin-bottom:15px; }
.section-title { font-family:var(--serif); font-size:1.35rem; font-weight:bold; color:var(--ink); border-bottom:2px solid var(--line-strong); padding-bottom:10px; margin:40px 0 20px; display:flex; align-items:center; gap:10px; }
.grid { display:grid; gap:20px; width:100%; }
.grid-3 { grid-template-columns:repeat(auto-fill, minmax(280px, 1fr)); }
.grid-2 { grid-template-columns:repeat(auto-fill, minmax(400px, 1fr)); }
a.card { text-decoration:none; color:inherit; display:flex; flex-direction:column; background:var(--card); border:1px solid var(--line); border-radius:16px; padding:24px; transition:all 0.2s ease; position:relative; overflow:hidden; box-shadow:0 2px 8px rgba(0,0,0,0.02); }
a.card:hover { transform:translateY(-4px); box-shadow:0 12px 24px -10px rgba(32,36,42,0.15); border-color:var(--line-strong); }
a.card.c-theta { border-top:5px solid var(--theta); }
a.card.c-r { border-top:5px solid var(--r); }
a.card.c-arc { border-top:5px solid var(--arc); }
a.card.c-dark { border-top:5px solid var(--ink); }
a.card h3 { margin:0 0 8px; font-size:1.15rem; color:var(--ink); border:none; padding:0; }
a.card p { margin:0; font-size:0.9rem; color:var(--muted); }
.chapter-num { font-family:Georgia, serif; font-size:2rem; font-weight:bold; opacity:0.2; position:absolute; top:10px; right:20px; }
a.card.special { background:linear-gradient(135deg, #fff, var(--tint)); border:1.5px solid var(--theta-soft); align-items:center; text-align:center; }
a.card.special h3 { color:var(--theta-ink); font-size:1.25rem; }
a.card.special-ex { border-color:var(--arc-soft); background:linear-gradient(135deg, #fff, #FFF9E6); }
a.card.special-ex h3 { color:var(--arc-ink); }
.icon { font-size:2rem; margin-bottom:10px; }

@media (max-width: 768px) {
  .app-container { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; padding: 20px; border-right: 0; border-bottom: 1px solid var(--line); }
  .main-content { margin-left: 0; padding: 20px; }
  .math-step { flex-direction: column; }
  .math-step .label { margin-bottom: 4px; font-weight: bold; color:var(--theta-ink); }
  .math-content { padding: 15px; }
  .hero h1 { font-size: 1.8rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .hub-container { padding: 30px 15px; }
}