:root { --bg: #fbfaf7; --fg: #26231f; --muted: #77716a; --line: #e4dfd6; --accent: #4a6b3f; }
@media (prefers-color-scheme: dark) {
  :root { --bg: #1b1a18; --fg: #ece8e1; --muted: #9b958c; --line: #3a3732; --accent: #9cc28f; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.7 system-ui, "Hiragino Sans", "Noto Sans JP", sans-serif; }
.site-header { padding: 14px 16px; border-bottom: 1px solid var(--line); letter-spacing: .15em; font-weight: 600; }
.site-header a { color: inherit; text-decoration: none; }
.karte { max-width: 640px; margin: 0 auto; padding: 24px 16px; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 32px 0 8px; }
.sci { font-style: italic; color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); font-size: .85rem; }
.facts { display: grid; grid-template-columns: 8em 1fr; gap: 6px 12px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
a { color: var(--accent); }
.history { width: 100%; border-collapse: collapse; }
.history th, .history td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; font-size: .9rem; }
.site-footer { text-align: center; padding: 32px 16px; color: var(--muted); font-size: .8rem; }

/* 血統図：左から右へ世代が進む。線は各枝の疑似要素で描く */
:root { --male: #4f7cac; --female: #b5657a; --tree: #bdb5a8; }
.ped-scroll { overflow-x: auto; padding: 8px 0 12px; }
.pn { display: flex; align-items: center; }
.pk { display: flex; flex-direction: column; margin-left: 18px; position: relative; }
.pk::before { content: ""; position: absolute; left: -18px; top: 50%; width: 18px; border-top: 1px solid var(--tree); }
.pb { position: relative; padding: 4px 0 4px 18px; display: flex; align-items: center; }
.pb::before { content: ""; position: absolute; left: 0; top: 50%; width: 18px; border-top: 1px solid var(--tree); }
.pb::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; border-left: 1px solid var(--tree); }
.pb:first-child::after { top: 50%; }
.pb:last-child::after { bottom: 50%; }
.pbox { display: flex; flex-direction: column; min-width: 92px; padding: 5px 10px; border: 1px solid var(--line);
  border-left: 3px solid var(--male); border-radius: 6px; color: inherit; text-decoration: none; background: var(--bg); font-size: .85rem; line-height: 1.35; }
.pbox.female { border-left-color: var(--female); }
.pbox.self { border-width: 2px; border-left-width: 4px; font-weight: 600; }
.pbox.unknown { border-style: dashed; color: var(--muted); }
.pbox.link { border-color: var(--accent); border-width: 2px; position: relative; padding-right: 22px; box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.pbox.link::after { content: "›"; position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.pbox.link .pvalue { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; }
.pbox.link:hover, .pbox.link:focus-visible { background: rgba(127,127,127,.12); }
.pbox-note { font-size: .75rem; color: var(--muted); margin: 6px 0 0; }
.plabel { font-size: .7rem; color: var(--muted); }
@media (prefers-color-scheme: dark) { :root { --tree: #5e584f; } }

.table-scroll { overflow-x: auto; }
.history td, .history th { white-space: nowrap; }
.chart { margin: 16px 0 0; }
.chart figcaption { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.kids-list { display: flex; flex-wrap: wrap; gap: 8px; }

/* 目次：スマホでは出さず、PC（幅900px以上）で左に固定表示 */
html { scroll-behavior: smooth; }
h2 { scroll-margin-top: 16px; }
h2.first { margin-top: 8px; }
.toc { display: none; }
@media (min-width: 900px) {
  .layout { display: flex; justify-content: center; align-items: flex-start; gap: 32px; padding: 0 24px; }
  .toc:not([hidden]) { display: flex; flex-direction: column; position: sticky; top: 24px; margin-top: 24px; width: 180px; flex: none;
    border-left: 2px solid var(--line); }
  .toc a { padding: 6px 12px; color: var(--muted); text-decoration: none; font-size: .9rem; line-height: 1.4; }
  .toc a:hover, .toc a:focus-visible { color: var(--accent); background: rgba(127,127,127,.1); }
  .karte { margin: 0; flex: 0 1 720px; min-width: 0; }
}

/* ライン（先祖）は右が自分：左右を反転して描く */
.rev .pn { flex-direction: row-reverse; }
.rev .pk { margin-left: 0; margin-right: 18px; }
.rev .pk::before { left: auto; right: -18px; }
.rev .pb { padding: 4px 18px 4px 0; }
.rev .pb::before { left: auto; right: 0; }
.rev .pb::after { left: auto; right: 0; border-left: 0; border-right: 1px solid var(--tree); }

/* 子の「○回目」ボタン */
button.pbox.group { flex-direction: row; align-items: center; gap: 8px; font: inherit; font-size: .85rem; cursor: pointer; color: inherit;
  border: 2px solid var(--accent); border-left-width: 2px; }
button.pbox.group:hover, button.pbox.group:focus-visible { background: rgba(127,127,127,.12); }
.chev { color: var(--accent); font-weight: 700; }
.ped-scroll > .pn { display: inline-flex; }
.rev .pb { justify-content: flex-end; }

/* ホーム画面 */
.home h3 { font-size: 1rem; margin: 20px 0 8px; scroll-margin-top: 16px; }
.summary { display: flex; gap: 12px; margin: 16px 0; }
.stat { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; }
.stat .num { font-size: 1.6rem; font-weight: 600; line-height: 1.2; }
.stat .lbl { font-size: .8rem; color: var(--muted); }
.worldmap { width: 100%; height: auto; display: block; background: rgba(127,127,127,.06); border-radius: 8px; }
.worldmap .land { fill: var(--line); stroke: var(--bg); stroke-width: .5; }
.worldmap .land.has { fill: var(--accent); cursor: pointer; }
.worldmap .land.has:hover, .worldmap .land.sel { stroke: var(--fg); stroke-width: 1.2; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { font: inherit; font-size: .8rem; padding: 3px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); color: inherit; cursor: pointer; }
.chip.on { border-color: var(--accent); background: rgba(127,127,127,.15); font-weight: 600; }
.filterbar { margin: 16px 0 0; font-weight: 600; }
.filterbar .chip { margin-left: 8px; }
.toc a.tg { font-weight: 600; color: var(--fg); margin-top: 6px; }
.toc a.ts { padding-left: 24px; }
@media (min-width: 900px) { .toc { max-height: calc(100vh - 48px); overflow-y: auto; } }
