/* ==========================================================
   AI Safety Lab — 共通スタイル
   方針: 画像なし・Webフォントなし・JSなし（数式ページのみKaTeX CDN）
   ========================================================== */

:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --text: #1c1917;
  --muted: #6b6560;
  --border: #e7e5e4;
  --accent: #2563eb;
  --accent-bg: #eff6ff;
  --code-bg: #f4f4f5;
  /* パートごとの識別色 */
  --p0: #64748b;
  --p1: #2563eb;
  --p2: #0d9488;
  --p3: #7c3aed;
  --p4: #c2410c;
  --p5: #dc2626;
  --pc: var(--accent);
  --maxw: 760px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --surface: #1c1c1c;
    --text: #e8e6e3;
    --muted: #a39e98;
    --border: #2f2f2f;
    --accent: #60a5fa;
    --accent-bg: #172033;
    --code-bg: #262626;
    --p0: #94a3b8;
    --p1: #60a5fa;
    --p2: #2dd4bf;
    --p3: #a78bfa;
    --p4: #fb923c;
    --p5: #f87171;
  }
}

.p0 { --pc: var(--p0); }
.p1 { --pc: var(--p1); }
.p2 { --pc: var(--p2); }
.p3 { --pc: var(--p3); }
.p4 { --pc: var(--p4); }
.p5 { --pc: var(--p5); }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.85;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }
img, svg { max-width: 100%; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

/* ---------- ヘッダー ---------- */
.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 4px 20px; padding-top: 12px; padding-bottom: 12px;
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; letter-spacing: 0.01em; }
.brand b { color: var(--p5); }
.site-header nav { display: flex; flex-wrap: wrap; gap: 2px 18px; font-size: 14px; }
.site-header nav a { color: var(--muted); text-decoration: none; }
.site-header nav a:hover { color: var(--text); }

/* サイト内検索（検索窓と結果の枠は assets/search.js が生成）。ヘッダーは上に固定して常に見せる */
.site-header { position: sticky; top: 0; z-index: 30; }
.site-header.has-search nav { order: 2; flex-basis: 100%; }
.site-search { order: 1; flex: 0 1 240px; margin-left: auto; }
.site-search input {
  width: 100%; font: inherit; font-size: 14px; line-height: 1.4; padding: 5px 11px;
  color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
}
.site-search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.search-panel {
  position: absolute; left: 0; right: 0; top: 100%; max-height: 70vh; overflow: auto;
  background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: 0 12px 28px rgba(0, 0, 0, 0.14);
}
.search-panel .wrap { display: block; padding-top: 10px; padding-bottom: 14px; }
.search-hint { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.search-list { list-style: none; }
.search-list li + li { border-top: 1px solid var(--border); }
.search-list a { display: block; padding: 8px 8px; border-radius: 6px; color: var(--text); text-decoration: none; }
.search-list a:hover, .search-list a:focus { background: var(--accent-bg); outline: none; }
.search-list small { display: block; font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.search-list b { font-weight: 600; font-size: 15px; line-height: 1.5; }
.search-list b i { font-style: normal; font-weight: 400; font-size: 13px; color: var(--muted); }
.search-list span { display: block; font-size: 13px; color: var(--muted); line-height: 1.6; }
.search-list mark { background: color-mix(in srgb, var(--accent) 24%, transparent); color: inherit; border-radius: 2px; }
.search-none { font-size: 14px; color: var(--muted); }
:root { --head: 96px; }             /* 固定ヘッダーの高さの目安（ページ内リンクで見出しが隠れないように） */
[id] { scroll-margin-top: var(--head); }

/* 言語切り替え（assets/i18n.js が中身を生成） */
.lang-switch { display: inline-flex; align-items: center; gap: 10px; padding-left: 14px; border-left: 1px solid var(--border); }
.lang-switch .cur { color: var(--text); font-weight: 600; }
.lang-switch a.missing { text-decoration: underline dotted; text-underline-offset: 3px; }
.lang-switch details { position: relative; }
.lang-switch summary { cursor: pointer; list-style: none; color: var(--text); }
.lang-switch details > div {
  position: absolute; right: 0; top: 2em; z-index: 10; display: grid; gap: 2px; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 14px;
}

/* 案内バー（ブラウザの言語版があるとき i18n.js が表示） */
.lang-offer { background: var(--accent-bg); border-bottom: 1px solid var(--border); font-size: 14px; }
.lang-offer .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding-top: 8px; padding-bottom: 8px; }
.lang-offer a { font-weight: 600; }
.lang-offer button {
  margin-left: auto; font: inherit; font-size: 13px; cursor: pointer;
  color: var(--muted); background: none; border: 1px solid var(--border); border-radius: 6px; padding: 1px 10px;
}

/* ルートの言語選択ページ */
.chooser { max-width: 420px; padding: 18vh 20px 40px; text-align: center; }
.chooser .brand { display: block; font-size: 26px; margin-bottom: 8px; }
.chooser p { color: var(--muted); font-size: 14.5px; }
.lang-choose { list-style: none; display: grid; gap: 10px; margin-top: 28px; }
.lang-choose a {
  display: block; padding: 12px; border-radius: 8px; font-size: 16px; font-weight: 600; text-decoration: none;
  color: var(--text); background: var(--surface); border: 1px solid var(--border);
}
.lang-choose a:hover { border-color: var(--accent); }

html:lang(en) body { line-height: 1.7; }

main { padding: 48px 0 24px; }
section { margin-bottom: 56px; }

h2 {
  font-size: 21px; font-weight: 700; margin-bottom: 18px;
  border-left: 3px solid var(--pc); padding-left: 12px; line-height: 1.5;
}
h3 { font-size: 17px; font-weight: 700; line-height: 1.5; }
.sec-lead { color: var(--muted); font-size: 15px; margin: -8px 0 20px; }

/* ---------- 表紙: ヒーロー ---------- */
.hero { margin-bottom: 36px; }
.eyebrow {
  font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-bg);
  display: inline-block; padding: 2px 9px; border-radius: 4px; margin-bottom: 14px;
}
.hero h1 { font-size: 32px; line-height: 1.4; letter-spacing: -0.01em; margin-bottom: 14px; }
.hero .lead { font-size: 16.5px; color: var(--muted); }
.hero-meta { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 13px; }
.hero-meta span { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 2px 12px; color: var(--muted); }

/* 表紙: 中心となる問い */
.question {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--p5);
  border-radius: 8px; padding: 20px 24px; margin-bottom: 56px;
}
.question .label { font-size: 12px; font-weight: 700; color: var(--p5); letter-spacing: 0.05em; }
.question .q { font-size: 20px; font-weight: 700; line-height: 1.6; margin: 4px 0 12px; }
.question p { font-size: 15px; }
.question small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 10px; line-height: 1.6; }

/* 表紙: ロードマップ */
.roadmap { list-style: none; display: grid; grid-template-columns: repeat(5, 1fr); gap: 20px; }
.roadmap li { position: relative; }
.roadmap li:not(:last-child)::after {
  content: "→"; position: absolute; right: -15px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 14px;
}
.roadmap a {
  display: block; height: 100%; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--pc);
  border-radius: 8px; padding: 12px 12px 14px; transition: border-color .15s;
}
.roadmap a:hover { border-color: var(--pc); }
.roadmap .step { display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em; color: var(--pc); }
.roadmap strong { display: block; font-size: 15px; line-height: 1.45; margin: 2px 0 6px; }
.roadmap .why { display: block; font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.roadmap-note { font-size: 13px; color: var(--muted); margin-top: 14px; }

/* 表紙: 学習ルート */
.routes { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.route {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-top: 4px solid var(--pc); border-radius: 10px; padding: 18px 20px 20px;
}
.route .icon { font-size: 30px; line-height: 1; margin-bottom: 10px; }
.route h3 { font-size: 17px; line-height: 1.4; margin-bottom: 4px; }
.route .who { font-size: 13px; color: var(--muted); margin-bottom: 16px; line-height: 1.6; }
.route .go {
  margin-top: auto; align-self: stretch; text-align: center; font-size: 14.5px; font-weight: 700; text-decoration: none;
  color: var(--surface); background: var(--pc); border-radius: 8px; padding: 9px 18px;
}
.route .go:hover { filter: brightness(1.1); }
.route .alt { font-size: 12.5px; color: var(--muted); margin-top: 10px; line-height: 1.6; }

/* 表紙: カリキュラム */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--muted); margin-bottom: 24px; }
.part { margin-bottom: 40px; }
.part-head { margin-bottom: 10px; }
.part-no { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--pc); text-transform: uppercase; }
.part-head h3 { font-size: 19px; }
.part-head h3 .en { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 8px; }
.part-head p { font-size: 14.5px; color: var(--muted); margin-top: 2px; }

.lessons { list-style: none; border-top: 1px solid var(--border); }
.lessons li > a:first-child, .lessons li > div {
  display: grid; grid-template-columns: 2.8em 1fr auto; gap: 10px; align-items: baseline;
  padding: 9px 6px; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none;
}
.lessons li > a:first-child:hover { background: var(--surface); }
.lessons li > a:first-child .ttl { text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 4px; }
.lessons li > a:first-child:hover .ttl { text-decoration-color: var(--pc); }
.lessons .no { font-size: 13.5px; font-weight: 700; color: var(--pc); font-variant-numeric: tabular-nums; }
.lessons .ttl { font-size: 15px; font-weight: 600; line-height: 1.6; }
.lessons .ttl small { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: .7em; }
.lessons .tags { display: flex; gap: 4px; }

.tag {
  display: inline-block; font-size: 11px; line-height: 1.7; white-space: nowrap;
  padding: 0 7px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted);
}
.tag.new { color: var(--accent); border-color: var(--accent); }
.tag.adv { color: var(--p3); border-color: var(--p3); }
.tag.upd { color: var(--p2); border-color: var(--p2); }
.tag.opt { border-style: dashed; }
.tag.ja { color: var(--accent); border-color: var(--accent); border-style: dashed; }
.tag.video { color: #dc2626; border-color: #dc2626; }
.tag.video.off { color: var(--muted); border-color: var(--border); border-style: dashed; cursor: default; }
/* 表紙の行：動画の印は YouTube への別リンク（行のリンクの中に入れ子にしない）。行の中には同じ幅の見えない印を置いて並びを保つ */
.lessons li.has-video { position: relative; }
.lessons .tag.video.ph { visibility: hidden; }
.lessons .tag.video.yt { position: absolute; right: 6px; top: 13px; text-decoration: none; }
.lessons .tag.video.yt:hover { background: #dc2626; color: #fff; }

/* 表紙: 付録・更新情報 */
.appendix { list-style: none; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.appendix li { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; }
.appendix strong { display: block; font-size: 14.5px; }
.appendix span { display: block; font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.appendix .tag { margin-top: 6px; }

.news { font-size: 14px; }
.news div { display: grid; grid-template-columns: 7.5em 1fr; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.news dt { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ヘッダーの「ニュース」リンクと、表紙上部の最新ニュース（assets/news.js が作る） */
.nav-news .tag { margin-left: 4px; font-size: 10.5px; padding: 0 5px; vertical-align: 1px; }
.news-flash {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin: 20px 0 24px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 8px; padding: 10px 16px; font-size: 14px;
}
.news-flash .label { font-size: 12px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.news-flash ul { list-style: none; flex: 1 1 260px; display: grid; gap: 2px; }
.news-flash a { color: var(--text); text-decoration: none; }
.news-flash a:hover { text-decoration: underline; }
.news-flash time { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 4px; }
.news-flash .tag, .ai-news-list .tag { margin-left: 6px; font-size: 10.5px; padding: 0 5px; vertical-align: 1px; }

/* 表紙：AI 安全のニュース（assets/news.js が中身を作る） */
.ai-news-list { list-style: none; }
.ai-news-list li { padding: 12px 0; border-bottom: 1px solid var(--border); }
.ai-news-list .meta { font-size: 12.5px; color: var(--muted); margin: 0 0 2px; font-variant-numeric: tabular-nums; }
.ai-news-list h3 { font-size: 15.5px; line-height: 1.5; margin: 0 0 4px; }
.ai-news-list h3 a { color: var(--text); text-decoration: none; }
.ai-news-list h3 a:hover { text-decoration: underline; }
.ai-news-list .sum { font-size: 14px; color: var(--muted); line-height: 1.7; margin: 0; }
.ai-news-empty { font-size: 14px; color: var(--muted); }
.ai-news-more {
  margin-top: 12px; font: inherit; font-size: 13.5px; cursor: pointer;
  color: var(--accent); background: none; border: 1px solid var(--border); border-radius: 6px; padding: 4px 14px;
}

/* ---------- フッター ---------- */
.site-footer { border-top: 1px solid var(--border); margin-top: 24px; padding: 24px 0 40px; font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.site-footer p + p { margin-top: 6px; }
.site-footer .counter { display: flex; align-items: center; gap: 8px; }
.site-footer .counter img { display: block; }

/* ==========================================================
   レッスンページ
   ========================================================== */
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 20px; }
.crumb a { color: var(--muted); }
.crumb i { font-style: normal; margin: 0 6px; }

.lesson-head { margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.lesson-head .part-no { display: block; margin-bottom: 6px; }
.lesson-head h1 { font-size: 26px; line-height: 1.45; margin-bottom: 4px; }
.lesson-head .sub { font-size: 16px; color: var(--muted); }
.lesson-head .meta { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--muted); margin-top: 12px; }

article section { margin-bottom: 40px; }
article h3 { margin: 28px 0 10px; }
article p { margin-bottom: 14px; }
article ul, article ol { padding-left: 1.4em; margin-bottom: 14px; }
article li { margin-bottom: 4px; }
article strong { font-weight: 700; }

.goals { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px 6px; margin-bottom: 36px; }
.goals h2 { font-size: 15px; border: 0; padding: 0; margin-bottom: 6px; color: var(--pc); }
.goals ul { font-size: 15px; }

.formula { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 16px; margin: 0 0 16px; }

figure { margin: 8px 0 20px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; overflow-x: auto; }
figcaption { font-size: 13px; color: var(--muted); margin-top: 8px; }
.fig-fg { fill: var(--text); }
.fig-muted { fill: var(--muted); }
.fig-hit { fill: var(--pc); }
.fig-miss { fill: var(--border); }
.fig-line { fill: none; stroke: var(--pc); stroke-width: 2.5; stroke-linejoin: round; }
.fig-axis { stroke: var(--muted); stroke-width: 1; }
.fig-grid { stroke: var(--border); stroke-width: 1; }
.fig-guide { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.fig-warn { fill: var(--p5); }
.fig-stop { stroke: var(--p5); stroke-width: 2; }
.fig-band1 { fill: color-mix(in srgb, var(--pc) 42%, transparent); }
.fig-band2 { fill: color-mix(in srgb, var(--pc) 16%, transparent); }

.keypoint { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--pc); border-radius: 8px; padding: 14px 20px 0; margin: 0 0 16px; }

.calc { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; display: grid; gap: 10px; font-size: 15px; }
.calc input, .calc select, .calc button {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px;
}
.calc input { width: 9em; }
.calc button { cursor: pointer; font-size: 13.5px; }
.calc button:hover { border-color: var(--pc); }
.calc p { margin: 0; }
.calc-out { border-top: 1px solid var(--border); padding-top: 10px; font-size: 16px; }
.calc-note { font-size: 12.5px; color: var(--muted); }

.ad-box {
  background: var(--accent-bg); border-radius: 8px; padding: 18px 22px 6px; margin-bottom: 40px;
  border: 1px solid color-mix(in srgb, var(--p5) 25%, transparent);
}
.ad-box h2 { font-size: 16px; border: 0; padding: 0; color: var(--p5); margin-bottom: 8px; }

details.quiz { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 18px; margin-bottom: 10px; }
details.quiz summary { cursor: pointer; font-weight: 600; font-size: 15px; }
details.quiz[open] summary { margin-bottom: 8px; }
details.quiz p { font-size: 15px; }

table { border-collapse: collapse; width: 100%; font-size: 14px; margin-bottom: 16px; }
th, td { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
.table-wrap { overflow-x: auto; }

code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 48px 0 8px; }
.pager > * { display: block; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 10px 14px; font-size: 14px; color: inherit; text-decoration: none; }
.pager a:hover { border-color: var(--pc); }
.pager small { display: block; font-size: 11.5px; color: var(--muted); }
.pager .next { text-align: right; }
.pager .off { color: var(--muted); }

/* ---------- 付録（用語集・記号表） ---------- */
.toc { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 14px; margin: 0 0 28px; }
dl.gloss { margin: 0; }
dl.gloss dt {
  font-weight: 700; margin: 18px 0 0 -6px; padding: 1px 6px; border-radius: 4px; scroll-margin-top: calc(var(--head) + 16px);
}
dl.gloss dt:target { background: var(--accent-bg); }
dl.gloss .alt { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 10px; }
dl.gloss dd { margin: 2px 0 0; font-size: 15px; }
dl.gloss .see { font-size: 13px; color: var(--muted); margin-left: 8px; }

/* ---------- お問い合わせフォーム ---------- */
.form { display: grid; gap: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 20px; }
.form label { display: grid; gap: 4px; font-size: 14.5px; font-weight: 600; }
.form .hint { font-size: 12.5px; font-weight: 400; color: var(--muted); }
.form input, .form select, .form textarea {
  width: 100%; font: inherit; font-weight: 400; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px;
}
.form textarea { min-height: 10em; resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.form button {
  justify-self: start; font: inherit; font-weight: 600; cursor: pointer;
  color: var(--surface); background: var(--accent); border: 0; border-radius: 6px; padding: 9px 24px;
}
.form .hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.req { font-size: 12px; font-weight: 600; color: var(--p5); }
.form-note { font-size: 13px; color: var(--muted); line-height: 1.7; margin: 0; }

/* ---------- スマホ ---------- */
@media (max-width: 720px) {
  main { padding-top: 32px; }
  .lang-switch { border-left: 0; padding-left: 0; }
  .site-search { flex: 1 1 120px; }
  :root { --head: 130px; }
  .hero h1 { font-size: 26px; }
  .roadmap { grid-template-columns: 1fr; gap: 18px; }
  .roadmap li:not(:last-child)::after { content: "↓"; right: auto; left: 50%; top: auto; bottom: -18px; transform: translateX(-50%); line-height: 18px; }
  .lessons .ttl small { display: block; margin-left: 0; }
  .lesson-head h1 { font-size: 22px; }
}
