/* ============================================================
   CS Visual Learning — デザインシステム
   全ページ共通。ダークモード自動対応（prefers-color-scheme）。
   ============================================================ */

:root {
  --bg: #f6f7fb;
  --bg-card: #ffffff;
  --bg-viz: #0f1420;          /* アニメーションキャンバスは常にダーク地 */
  --bg-code: #f0f2f8;
  --text: #1c2333;
  --text-sub: #5b6478;
  --line: #e2e6f0;
  --accent: #3b6cf6;
  --accent-soft: #e8eeff;
  --green: #16a34a;  --green-soft: #e6f6ec;
  --amber: #d97706;  --amber-soft: #fdf1df;
  --red: #dc2626;    --red-soft: #fdeaea;
  --purple: #7c3aed; --purple-soft: #f1eafd;
  --shadow: 0 1px 3px rgba(20, 30, 60, .08), 0 8px 24px rgba(20, 30, 60, .06);
  --radius: 14px;
  --sidebar-w: 280px;
  --header-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-card: #161c26;
    --bg-viz: #0a0e16;
    --bg-code: #1b2230;
    --text: #e6e9f2;
    --text-sub: #9aa3b8;
    --line: #2a3242;
    --accent: #6b93ff;
    --accent-soft: #1c2740;
    --green: #34d47b;  --green-soft: #12301f;
    --amber: #f5a742;  --amber-soft: #33260f;
    --red: #f26d6d;    --red-soft: #361518;
    --purple: #a97ef7; --purple-soft: #251a3a;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI",
               "Noto Sans JP", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.85;
  font-size: 15.5px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- ヘッダー ---------- */
.site-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg-card) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.site-header .logo {
  font-weight: 800; font-size: 16px; text-decoration: none; color: var(--text);
  display: flex; align-items: center; gap: 8px; white-space: nowrap;
}
.site-header .logo .logo-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; font-weight: 800;
}
.site-header nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: thin; }
.site-header nav a {
  text-decoration: none; color: var(--text-sub); font-size: 12.5px; font-weight: 600;
  padding: 5px 8px; border-radius: 8px; white-space: nowrap;
}
.site-header nav a:hover { background: var(--accent-soft); color: var(--accent); }
.site-header nav a.active { background: var(--accent-soft); color: var(--accent); }
.header-spacer { flex: 1; }

/* ---------- レイアウト ---------- */
.layout {
  display: flex; gap: 0;
  max-width: 1280px; margin: 0 auto;
  padding-top: var(--header-h);
}
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 24px 14px 40px;
  border-right: 1px solid var(--line);
}
main.content {
  flex: 1; min-width: 0;
  padding: 32px 40px 80px;
}
@media (max-width: 900px) {
  .sidebar { display: none; }
  main.content { padding: 24px 16px 60px; }
}

/* ---------- サイドバー ---------- */
.sidebar .level-group { margin-bottom: 18px; }
.sidebar .level-title {
  font-size: 11.5px; font-weight: 800; letter-spacing: .08em;
  padding: 4px 10px; margin-bottom: 4px;
  display: flex; align-items: center; gap: 6px;
}
.sidebar .level-title.l1 { color: var(--green); }
.sidebar .level-title.l2 { color: var(--amber); }
.sidebar .level-title.l3 { color: var(--red); }
.sidebar a.lesson-link {
  display: flex; align-items: baseline; gap: 8px;
  text-decoration: none; color: var(--text-sub);
  font-size: 13.5px; padding: 6px 10px; border-radius: 8px; line-height: 1.5;
}
.sidebar a.lesson-link:hover { background: var(--accent-soft); color: var(--accent); }
.sidebar a.lesson-link.current { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.sidebar a.lesson-link .num { font-size: 11px; font-weight: 700; opacity: .65; flex-shrink: 0; }
.sidebar a.lesson-link .done { margin-left: auto; color: var(--green); font-size: 12px; }

/* ---------- パンくず・レッスンヘッダー ---------- */
.breadcrumb { font-size: 12.5px; color: var(--text-sub); margin-bottom: 14px; }
.breadcrumb a { color: var(--text-sub); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }

.lesson-header { margin-bottom: 28px; }
.lesson-header h1 { font-size: 27px; line-height: 1.4; margin: 8px 0 10px; }
.lesson-header .lede { color: var(--text-sub); font-size: 15px; }

.level-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 800; letter-spacing: .05em;
  padding: 3px 10px; border-radius: 999px;
}
.level-badge.l1 { background: var(--green-soft); color: var(--green); }
.level-badge.l2 { background: var(--amber-soft); color: var(--amber); }
.level-badge.l3 { background: var(--red-soft); color: var(--red); }

/* ---------- 本文 ---------- */
main.content h2 {
  font-size: 20px; margin: 44px 0 14px;
  padding-left: 12px; border-left: 4px solid var(--accent);
  line-height: 1.5;
}
main.content h3 { font-size: 16.5px; margin: 28px 0 10px; }
main.content p { margin: 10px 0; }
main.content ul, main.content ol { margin: 10px 0 10px 24px; }
main.content li { margin: 4px 0; }
main.content strong { font-weight: 700; }
main.content a { color: var(--accent); }

/* ---------- ビジュアライゼーションカード ---------- */
.viz-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 20px 0 26px;
  overflow: hidden;
}
.viz-card .viz-title {
  padding: 12px 18px;
  font-size: 13.5px; font-weight: 700;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
}
.viz-card .viz-title::before { content: "▶"; color: var(--accent); font-size: 10px; }
.viz-card canvas {
  display: block; width: 100%;
  background: var(--bg-viz);
}
.viz-card .viz-note {
  padding: 10px 18px; font-size: 12.5px; color: var(--text-sub);
  border-top: 1px solid var(--line);
}

/* ---------- コントロール ---------- */
.controls {
  display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: center;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 55%, var(--bg-card));
}
.controls .ctl { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-sub); }
.controls .ctl b { color: var(--text); font-weight: 700; min-width: 2.5em; text-align: right; font-variant-numeric: tabular-nums; }
.controls label { font-weight: 600; white-space: nowrap; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 140px; height: 4px; border-radius: 2px;
  background: var(--line); outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2.5px solid var(--bg-card);
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
}

button.btn {
  font: inherit; font-size: 13px; font-weight: 700;
  padding: 7px 16px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line);
  background: var(--bg-card); color: var(--text);
  transition: transform .06s;
}
button.btn:hover { border-color: var(--accent); color: var(--accent); }
button.btn:active { transform: scale(.96); }
button.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.btn.primary:hover { filter: brightness(1.1); color: #fff; }
select.sel {
  font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg-card); color: var(--text);
}

/* ---------- コールアウト ---------- */
.callout {
  border-radius: 12px; padding: 14px 18px; margin: 18px 0;
  font-size: 14px; border: 1px solid transparent;
}
.callout .co-title { font-weight: 800; font-size: 12.5px; letter-spacing: .04em; margin-bottom: 4px; display: block; }
.callout.point { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.callout.point .co-title { color: var(--accent); }
.callout.warn { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 30%, transparent); }
.callout.warn .co-title { color: var(--amber); }
.callout.deep { background: var(--purple-soft); border-color: color-mix(in srgb, var(--purple) 25%, transparent); }
.callout.deep .co-title { color: var(--purple); }

/* ---------- 数式・コード ---------- */
.formula {
  background: var(--bg-code); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 20px; margin: 14px 0;
  font-family: "STIX Two Math", "Cambria Math", Georgia, serif;
  font-size: 17px; text-align: center; overflow-x: auto;
}
.formula .fnote { font-family: inherit; font-size: 12px; color: var(--text-sub); display: block; margin-top: 6px; }
code {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: .88em; background: var(--bg-code);
  padding: 2px 6px; border-radius: 5px;
}
pre {
  background: var(--bg-code); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 18px; margin: 14px 0;
  overflow-x: auto; line-height: 1.6;
}
pre code { background: none; padding: 0; font-size: 13px; }
sub, sup { font-size: .72em; }

/* ---------- 前後ナビ・完了ボタン ---------- */
.lesson-footer { margin-top: 56px; }
.done-row { text-align: center; margin-bottom: 22px; }
.prevnext { display: flex; gap: 14px; }
.prevnext a {
  flex: 1; text-decoration: none;
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 18px;
  color: var(--text); box-shadow: var(--shadow);
}
.prevnext a:hover { border-color: var(--accent); }
.prevnext .dir { font-size: 11.5px; color: var(--text-sub); font-weight: 700; letter-spacing: .06em; }
.prevnext .ttl { font-size: 14px; font-weight: 700; margin-top: 2px; }
.prevnext a.next { text-align: right; }
.prevnext a.spacer { visibility: hidden; }

/* ---------- カテゴリインデックス ---------- */
.cat-hero { margin: 10px 0 30px; }
.cat-hero h1 { font-size: 30px; margin-bottom: 8px; }
.cat-hero p { color: var(--text-sub); max-width: 640px; }
.path-level { margin-bottom: 34px; }
.path-level > h2 { border: none; padding: 0; font-size: 15px; display: flex; align-items: center; gap: 10px; margin: 0 0 12px; }
.lesson-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
a.lesson-card {
  text-decoration: none; color: var(--text);
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow); transition: transform .12s, border-color .12s;
  display: block;
}
a.lesson-card:hover { transform: translateY(-2px); border-color: var(--accent); }
a.lesson-card .lc-num { font-size: 11px; font-weight: 800; color: var(--text-sub); letter-spacing: .08em; }
a.lesson-card .lc-title { font-size: 15.5px; font-weight: 700; margin: 4px 0 6px; line-height: 1.5; }
a.lesson-card .lc-desc { font-size: 12.5px; color: var(--text-sub); line-height: 1.6; }
a.lesson-card .lc-done { float: right; color: var(--green); font-weight: 800; font-size: 12px; }

/* ---------- トップページ ---------- */
.home-hero {
  text-align: center; padding: 60px 20px 30px; position: relative;
}
.home-hero h1 { font-size: 34px; line-height: 1.4; }
.home-hero p { color: var(--text-sub); max-width: 620px; margin: 12px auto 0; }
.home-hero .hero-canvas-wrap {
  max-width: 860px; margin: 28px auto 0;
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.home-hero canvas { display: block; width: 100%; background: var(--bg-viz); }
.cat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px; max-width: 1020px; margin: 40px auto 80px; padding: 0 20px;
}
a.cat-card {
  text-decoration: none; color: var(--text);
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: 16px; padding: 24px;
  box-shadow: var(--shadow); transition: transform .14s, border-color .14s;
}
a.cat-card:hover { transform: translateY(-3px); border-color: var(--accent); }
a.cat-card .cc-icon { font-size: 30px; }
a.cat-card h2 { font-size: 18px; margin: 10px 0 6px; }
a.cat-card p { font-size: 13px; color: var(--text-sub); line-height: 1.7; }
a.cat-card .cc-meta { margin-top: 12px; font-size: 12px; color: var(--text-sub); display: flex; justify-content: space-between; align-items: center; }
a.cat-card .cc-bar { height: 5px; border-radius: 3px; background: var(--line); margin-top: 6px; overflow: hidden; }
a.cat-card .cc-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--purple)); border-radius: 3px; }
a.cat-card.coming { opacity: .55; pointer-events: none; }
a.cat-card .cc-soon {
  display: inline-block; font-size: 10.5px; font-weight: 800; letter-spacing: .06em;
  background: var(--line); color: var(--text-sub);
  padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: middle;
}

/* ---------- 比較テーブル ---------- */
.table-wrap { overflow-x: auto; margin: 16px 0; }
table.cmp {
  border-collapse: collapse; width: 100%; font-size: 13.5px;
  background: var(--bg-card); border-radius: 12px; overflow: hidden;
  box-shadow: var(--shadow);
}
table.cmp th, table.cmp td { padding: 10px 14px; border: 1px solid var(--line); text-align: left; }
table.cmp th { background: var(--bg-code); font-size: 12.5px; }

/* ---------- 参考書籍 ---------- */
.book-sec { margin-top: 36px; }
.book-sec .bk-head { font-size: 13.5px; font-weight: 800; margin-bottom: 2px; }
.book-sec .bk-sub { font-size: 11.5px; color: var(--text-sub); margin-bottom: 10px; }
.book-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
a.book-card {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 13px;
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 11px;
  text-decoration: none; color: var(--text);
  transition: border-color .12s;
}
a.book-card:hover { border-color: var(--accent); }
a.book-card .bk-emoji { font-size: 19px; line-height: 1.3; }
/* 疑似表紙（実画像が無い/読めない場合のフォールバック兼デフォルト） */
.bk-cover {
  flex: 0 0 44px; width: 44px; height: 62px;
  border-radius: 2px 4px 4px 2px;
  display: flex; align-items: center;
  padding: 5px 4px 5px 8px; position: relative; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.bk-cover::before {
  content: ""; position: absolute; left: 3px; top: 0; bottom: 0; width: 1.5px;
  background: rgba(255,255,255,.4);
}
.bk-cover i {
  font-style: normal; font-size: 7.5px; line-height: 1.4; font-weight: 700;
  color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.3);
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden;
}
.bk-cover.l1 { background: linear-gradient(140deg, #34a866, #1d7c4b); }
.bk-cover.l2 { background: linear-gradient(140deg, #e79a38, #bd6f14); }
.bk-cover.l3 { background: linear-gradient(140deg, #db5f6a, #a63a47); }
/* 実表紙画像（books.js の img 設定時） */
.bk-img {
  flex: 0 0 44px; width: 44px; height: 62px; object-fit: cover;
  border-radius: 2px 4px 4px 2px; border: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(0,0,0,.2); background: #fff;
}
a.book-card .bk-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
a.book-card .bk-title { font-size: 13px; font-weight: 700; line-height: 1.45; }
a.book-card .bk-meta { font-size: 11px; color: var(--text-sub); }
a.book-card .bk-why { font-size: 11.5px; color: var(--text-sub); line-height: 1.55; margin-top: 3px; }
.bk-disclosure { font-size: 10.5px; color: var(--text-sub); margin-top: 8px; opacity: .8; }

/* ---------- フッター ---------- */
.site-footer {
  border-top: 1px solid var(--line);
  padding: 26px 20px; text-align: center;
  font-size: 12.5px; color: var(--text-sub);
}
