/* ---------- tokens ---------- */
:root {
  --bg: #f4f7f6;
  --panel: #e7ebea;
  --surface: #ffffff;
  --ink: #222222;
  --ink-2: #555b59;
  --muted: #8a9290;
  --line: #d8dedc;
  --line-strong: #222222;
  --font: "Dosis", "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", sans-serif;
  --font-ja: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", sans-serif;
  --radius: 4px;
  --gutter: 32px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
body.locked { overflow: hidden; }
button { font: inherit; color: inherit; }
svg { display: block; }
svg path[data-icon], .ico { fill: currentColor; }

/* ---------- header ---------- */
.site-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 20px var(--gutter);
  height: 80px;
}
.logo {
  grid-column: 2;
  display: flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none;
}
.logo-mark { width: 34px; height: 34px; }
.logo-mark rect { fill: var(--ink); }
.logo-mark circle { fill: var(--bg); }
.logo-text { font-weight: 800; font-size: 26px; letter-spacing: .01em; line-height: 1; }
.header-meta {
  grid-column: 3; justify-self: end;
  font-weight: 600; font-size: 15px; letter-spacing: .03em;
}

.page { padding: 0 var(--gutter) 80px; }

/* ---------- filter bar ---------- */
.filter-bar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 22px 30px;
}
.search {
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid #b9c1bf;
  padding: 4px 2px;
  width: 180px;
  margin-right: 8px;
}
.search svg { width: 22px; height: 22px; color: var(--ink-2); flex: none; }
.search input {
  border: 0; background: transparent; outline: none; width: 100%;
  font: 600 15px var(--font); color: var(--ink); letter-spacing: .02em;
}
.search input::placeholder { color: var(--muted); }
.search:focus-within { border-color: var(--ink); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; flex: 1; }
.dd { position: relative; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  height: 36px; padding: 0 16px 0 10px;
  border: 1px solid #c3cbc9; border-radius: 999px;
  background: transparent; cursor: pointer;
  font-family: var(--font-ja); font-weight: 700; font-size: 14px; letter-spacing: .02em; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.pill svg { width: 20px; height: 20px; transition: transform .2s var(--ease); }
.pill:hover { border-color: var(--ink); }
.pill[aria-expanded="true"] svg { transform: rotate(180deg); }
.pill.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.pill .n {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  margin-left: 4px; border-radius: 10px; background: #fff; color: var(--ink); font-size: 12px;
}

.menu {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 20;
  min-width: 240px; max-height: 60vh; overflow: auto;
  background: var(--surface); border-radius: 8px; padding: 8px;
  box-shadow: 0 10px 40px rgb(0 0 0 / .12), 0 0 0 1px rgb(0 0 0 / .04);
  opacity: 0; transform: translateY(-4px); pointer-events: none;
  transition: opacity .15s, transform .15s var(--ease);
}
.dd.open .menu { opacity: 1; transform: none; pointer-events: auto; }
.opt {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; background: none; text-align: left; cursor: pointer;
  padding: 8px 10px; border-radius: 6px; font-family: var(--font-ja); font-size: 14px;
}
.opt:hover { background: var(--bg); }
.opt .box {
  width: 18px; height: 18px; border: 1.5px solid #b9c1bf; border-radius: 4px; flex: none;
  display: grid; place-items: center; color: #fff;
}
.opt .box svg { width: 14px; height: 14px; opacity: 0; }
.opt[aria-checked="true"] .box { background: var(--ink); border-color: var(--ink); }
.opt[aria-checked="true"] .box svg { opacity: 1; }
.opt .sw { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.opt .sub { margin-left: auto; color: var(--muted); font-family: var(--font); font-weight: 600; font-size: 13px; }

.reset {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: none; cursor: pointer; color: var(--muted);
  font-weight: 600; font-size: 15px; letter-spacing: .02em; margin-left: auto;
}
.reset svg { width: 20px; height: 20px; }
.reset:hover { color: var(--ink); }

/* ---------- list head ---------- */
.list-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 22px 0 26px;
}
.count { margin: 0; font-weight: 600; font-size: 15px; letter-spacing: .03em; }
.count b { font-weight: 700; }
.toggles { display: flex; gap: 14px; }
.toggle { display: flex; background: var(--panel); border-radius: var(--radius); padding: 4px; gap: 2px; }
.toggle button {
  width: 40px; height: 32px; border: 0; border-radius: 3px; background: transparent; cursor: pointer;
  display: grid; place-items: center; color: var(--ink);
}
.toggle button svg { width: 22px; height: 22px; }
.toggle button[aria-pressed="true"] { background: var(--surface); }

/* ---------- chapter blocks ---------- */
.chapter { margin-bottom: 64px; }
.chapter-head {
  display: grid; grid-template-columns: auto 1fr; column-gap: 20px; align-items: end;
  padding-bottom: 18px; margin-bottom: 26px; border-bottom: 1px solid var(--line);
}
.chapter-no {
  grid-row: span 2;
  font-weight: 800; font-size: 64px; line-height: .8; letter-spacing: -.02em;
  color: var(--c);
}
.chapter-title { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.chapter-title h2 { margin: 0; font-family: var(--font-ja); font-weight: 700; font-size: 24px; line-height: 1.3; }
.chapter-title .en { font-weight: 600; font-size: 15px; color: var(--muted); letter-spacing: .04em; }
.chapter-sum { margin: 6px 0 0; color: var(--ink-2); font-family: var(--font-ja); font-size: 14px; max-width: 720px; }

/* ---------- cards ---------- */
.grid {
  display: grid; gap: 52px 34px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.list[data-size="s"] .grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 36px 22px; }

.card {
  display: block; width: 100%; padding: 0; border: 0; background: none; text-align: left; cursor: pointer;
  opacity: 0; transform: translateY(12px);
  animation: rise .5s var(--ease) forwards;
  animation-delay: calc(var(--i, 0) * 25ms);
}
@keyframes rise { to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .card { animation: none; opacity: 1; transform: none; } }

.thumb {
  position: relative; display: block; aspect-ratio: 4 / 3; border-radius: var(--radius); overflow: hidden;
  background: var(--c); color: var(--fg);
}
.thumb svg.poster {
  position: absolute; inset: 12% 10% 10%; width: 80%; height: 78%;
  transition: transform .5s var(--ease);
}
.card:hover .thumb svg.poster { transform: scale(1.05); }
.card:focus-visible { outline: none; }
.card:focus-visible .thumb { outline: 3px solid var(--ink); outline-offset: 3px; }
.thumb .tid {
  position: absolute; left: 12px; top: 9px;
  font-weight: 700; font-size: 13px; letter-spacing: .06em; opacity: .85;
}
.list[data-size="s"] .thumb .tid { font-size: 11px; left: 9px; top: 6px; }
.card-name {
  display: block; margin-top: 12px;
  font-family: var(--font-ja); font-weight: 700; font-size: 15px; line-height: 1.5;
}
.card-en { display: block; font-weight: 600; font-size: 13px; color: var(--muted); letter-spacing: .03em; }
.list[data-size="s"] .card-name { font-size: 13px; margin-top: 8px; }
.list[data-size="s"] .card-en { display: none; }

.empty { padding: 80px 0; text-align: center; color: var(--muted); font-family: var(--font-ja); }

/* poster (thumbnail diagram) */
.poster .p-wire { stroke: var(--fg); stroke-width: 3; fill: none; opacity: .55; stroke-linecap: round; }
.poster .p-head { fill: var(--fg); opacity: .55; }
.poster .p-node { fill: var(--surface); }
.poster .p-node.hub { fill: var(--fg); }
.poster .p-ico { fill: var(--c); }
.poster .p-ico.hub { fill: var(--c); }

/* ---------- footer ---------- */
.site-footer {
  padding: 28px var(--gutter) 40px; border-top: 1px solid var(--line);
  color: var(--muted); font-family: var(--font-ja); font-size: 12px;
}
.site-footer p { margin: 0; }

/* ---------- detail (modal) ---------- */
.detail {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  padding: 24px;
}
.detail[hidden] { display: none; }
.backdrop {
  position: absolute; inset: 0; cursor: pointer;
  background: rgb(24 28 27 / .55);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  opacity: 0; transition: opacity .25s var(--ease);
}
.detail.show .backdrop { opacity: 1; }

.modal-wrap {
  position: relative; display: flex; justify-content: center;
  width: 100%; max-width: 1440px;
  pointer-events: none; /* 余白クリックは backdrop へ通す */
}
.modal-wrap > * { pointer-events: auto; }

/* 高さはメカニクスによらず固定。中身は内側でスクロールさせる */
.modal {
  position: relative; flex: 1; max-width: 1400px;
  height: min(880px, calc(100dvh - 48px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(400px, 34%, 480px);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "stage side" "stage foot";
  background: var(--bg); border-radius: 14px; overflow: hidden;
  box-shadow: 0 30px 80px rgb(0 0 0 / .28);
  opacity: 0; transform: translateY(18px) scale(.985);
  transition: opacity .25s var(--ease), transform .35s var(--ease);
}
.detail.show .modal { opacity: 1; transform: none; }
.modal-main { display: contents; }

.detail-stage { grid-area: stage; display: flex; min-height: 0; padding: 26px; }
.board {
  flex: 1; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 8px solid var(--ink); border-radius: 24px;
  padding: 22px 26px 18px;
  background-image: radial-gradient(circle, #e3e8e6 1.2px, transparent 1.3px);
  background-size: 22px 22px;
}
.board-top { display: flex; align-items: center; gap: 10px; flex: none; }
.board-chip {
  display: inline-flex; align-items: center; height: 28px; padding: 0 12px; border-radius: 999px;
  background: var(--c); color: var(--fg); font-weight: 700; font-size: 13px; letter-spacing: .05em;
}
.board-type { font-weight: 600; font-size: 13px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.board figure { flex: 1; min-height: 0; margin: 0; display: flex; flex-direction: column; }
.board svg.dia { flex: 1; min-height: 0; width: 100%; height: 100%; padding: 10px 0; }
.board figcaption {
  flex: none; text-align: center; font-family: var(--font-ja); font-weight: 500; font-size: 15px; color: var(--ink-2);
}

.dia .d-wire { stroke: var(--ink); stroke-width: 2.4; fill: none; stroke-linecap: round; }
.dia .d-head { fill: var(--ink); }
.dia .d-card { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.dia .d-card.hub { fill: var(--c); }
.dia .d-badge { fill: var(--c); }
.dia .d-badge.hub { fill: var(--surface); }
.dia .d-ico { fill: var(--fg); }
.dia .d-ico.hub { fill: var(--c); }
.dia .d-label { fill: var(--ink); font-family: var(--font-ja); font-weight: 700; }
.dia .d-label.hub { fill: var(--fg); }
.dia .d-pill { fill: var(--surface); stroke: var(--ink); stroke-width: 1.4; }
.dia .d-elabel { fill: var(--ink); font-family: var(--font-ja); font-weight: 700; font-size: 13px; }

.side-scroll {
  grid-area: side; min-height: 0; overflow: auto; overscroll-behavior: contain;
  border-left: 1px solid var(--line);
  padding: 26px 28px 28px;
}
.side-meta { display: flex; align-items: center; gap: 8px; padding-right: 48px; }
.side-date { font-weight: 600; font-size: 14px; letter-spacing: .06em; color: var(--ink-2); }
.icon-btn {
  width: 30px; height: 30px; border: 0; border-radius: 50%; background: none; cursor: pointer;
  display: grid; place-items: center; color: var(--muted); transition: background .15s, color .15s;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--panel); color: var(--ink); }
.side-title { margin: 6px 0 0; font-family: var(--font-ja); font-weight: 700; font-size: 26px; line-height: 1.35; }
.side-en { font-weight: 600; font-size: 15px; color: var(--muted); letter-spacing: .03em; }
.side-lead { margin: 14px 0 0; padding-bottom: 4px; font-family: var(--font-ja); font-weight: 500; font-size: 15px; line-height: 1.85; }
.attr { margin-top: 18px; }
.attr-k { font-family: var(--font-ja); font-weight: 700; font-size: 13px; color: var(--ink-2); letter-spacing: .04em; margin-bottom: 8px; }
.attr-k::after { content: "："; }
.attr-row { display: grid; grid-template-columns: repeat(3, auto); justify-content: start; gap: 18px; margin-top: 18px; }
.attr-row .attr { margin-top: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 13px;
  border: 1px solid #c3cbc9; border-radius: 999px; background: transparent;
  font-family: var(--font-ja); font-weight: 700; font-size: 12.5px; white-space: nowrap;
}
button.tag { cursor: pointer; transition: border-color .15s, background .15s; }
button.tag:hover { border-color: var(--ink); background: var(--surface); }
.tag .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.tag .rid { font-family: var(--font); font-weight: 700; color: var(--muted); }
.meter { display: inline-flex; gap: 3px; }
.meter i { width: 12px; height: 5px; border-radius: 3px; background: #d4dad8; }
.meter i.on { background: var(--ink); }
.prose { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); font-family: var(--font-ja); font-size: 14.5px; line-height: 1.9; }
.prose p:last-child, .prose ul:last-child { margin-bottom: 0; }
.attrs { margin-top: 20px; padding-top: 2px; border-top: 1px solid var(--line); }
.prose h3 { margin: 0 0 6px; font-family: var(--font); font-weight: 700; font-size: 14px; letter-spacing: .06em; }
.prose p { margin: 0 0 18px; color: var(--ink-2); }
.prose ul { margin: 0 0 18px; padding-left: 1.1em; color: var(--ink-2); }
.prose li + li { margin-top: 4px; }

/* 前後移動のフッター（常に同じ位置） */
.side-foot {
  grid-area: foot; display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 10px;
  padding: 14px 16px; border-left: 1px solid var(--line); border-top: 1px solid var(--line);
  background: var(--bg);
}
.prev-btn {
  border: 0; border-radius: 10px; background: var(--surface); cursor: pointer;
  display: grid; place-items: center; transition: background .15s;
}
.prev-btn svg { width: 26px; height: 26px; }
.prev-btn:hover { background: #e9eeec; }
.next-card {
  display: grid; grid-template-columns: 76px minmax(0, 1fr) 28px; align-items: center; gap: 12px;
  height: 68px; padding: 6px 8px 6px 6px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--ink); color: #fff; text-align: left; transition: background .15s;
}
.next-card:hover { background: #000; }
.next-card .mini {
  position: relative; height: 56px; border-radius: 6px; overflow: hidden; background: var(--c); color: var(--fg);
}
.next-card .mini svg.poster { inset: 10%; width: 80%; height: 80%; }
.next-k { display: block; font-weight: 700; font-size: 12px; letter-spacing: .08em; opacity: .7; }
.next-name { display: block; font-family: var(--font-ja); font-weight: 700; font-size: 15px; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.next-card > svg { width: 26px; height: 26px; transition: transform .2s var(--ease); }
.next-card:hover > svg { transform: translateX(3px); }

.close {
  position: absolute; top: 16px; right: 16px; z-index: 2;
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--ink); color: #fff; display: grid; place-items: center;
  transition: transform .2s var(--ease);
}
.close svg { width: 22px; height: 22px; }
.close:hover { transform: rotate(90deg); }
.close:focus-visible, .next-card:focus-visible, .prev-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.close:focus:not(:focus-visible) { outline: none; }

/* 前後移動したときの切り替えアニメーション */
@keyframes swap-in { from { opacity: 0; transform: translateX(calc(var(--dir, 1) * 18px)); } to { opacity: 1; transform: none; } }
.modal.swap .board > *, .modal.swap .side-scroll > * { animation: swap-in .32s var(--ease) both; }
@media (prefers-reduced-motion: reduce) { .modal.swap .board > *, .modal.swap .side-scroll > * { animation: none; } }

.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 60; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-family: var(--font-ja); font-size: 13px; font-weight: 500;
  opacity: 0; transition: opacity .2s, transform .2s var(--ease); pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .list[data-size="s"] .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 1000px) {
  /* 縦積み：図解と説明は1つのスクロール領域、前後移動は下に固定 */
  .detail { padding: 14px; }
  .modal {
    height: calc(100dvh - 28px);
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "main" "foot";
  }
  .modal-main { display: block; grid-area: main; overflow: auto; overscroll-behavior: contain; }
  .detail-stage { height: min(62dvh, 560px); padding: 60px 14px 0; }
  .side-scroll { overflow: visible; border-left: 0; padding: 20px 20px 24px; }
  .side-meta { padding-right: 0; }
  .side-foot { border-left: 0; padding: 10px 12px; }
}
@media (max-width: 760px) {
  :root { --gutter: 16px; }
  .site-header { height: 64px; padding: 12px var(--gutter); grid-template-columns: auto 1fr; }
  .logo { grid-column: 1; }
  .header-meta { grid-column: 2; font-size: 13px; }
  .logo-text { font-size: 22px; }
  .logo-mark { width: 28px; height: 28px; }
  .filter-bar { padding: 16px; gap: 12px; }
  .search { width: 100%; margin: 0; }
  .filters { gap: 8px; }
  .pill { height: 34px; font-size: 14px; padding-right: 12px; }
  .reset { margin-left: 0; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px 14px; }
  .list[data-size="s"] .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px 10px; }
  .chapter-no { font-size: 44px; }
  .chapter-title h2 { font-size: 20px; }
  .board { border-width: 5px; border-radius: 18px; padding: 14px 10px 12px; }
  .board figcaption { font-size: 13px; }
  .side-scroll { padding: 18px 16px 20px; }
  .side-title { font-size: 22px; }
  .attr-row { gap: 12px; }
  .menu { position: fixed; left: 16px; right: 16px; top: auto; min-width: 0; }
}
