:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-code: #f4f5f7;
  --fg: #1c1f26;
  --fg-muted: #5b6472;
  --fg-faint: #8a929e;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --accent: #1f4e9c;
  --accent-soft: #eaf0fa;
  --warn-bg: #fff8e6;
  --warn-border: #e8cf8a;
  --radius: 8px;
  --maxw: 1180px;
  --sans: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Noto Sans JP",
    system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --bg-soft: #1b1f26;
    --bg-code: #1e232b;
    --fg: #e3e6ea;
    --fg-muted: #a4adba;
    --fg-faint: #7b8595;
    --border: #2b313a;
    --border-strong: #3b434f;
    --accent: #8db4f0;
    --accent-soft: #1c2634;
    --warn-bg: #2a2417;
    --warn-border: #5c4d24;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.85;
  font-feature-settings: "palt" 1;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  text-decoration-thickness: 2px;
}

/* ---------- ヘッダ ---------- */

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}

.site-header .inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  align-items: baseline;
}

.site-header .brand {
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--fg);
  text-decoration: none;
}

.site-header .brand span {
  color: var(--fg-muted);
  font-weight: 400;
  font-size: 0.85rem;
  margin-left: 0.5rem;
}

.site-header nav {
  margin-left: auto;
  display: flex;
  gap: 1rem;
  font-size: 0.88rem;
}

/* ---------- レイアウト ---------- */

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 3rem;
  align-items: start;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.5rem;
  }
}

/* ---------- 目次 ---------- */

.toc {
  position: sticky;
  top: 1.5rem;
  font-size: 0.85rem;
  line-height: 1.6;
  border-left: 2px solid var(--border);
  padding-left: 1rem;
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
}

.toc h2 {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  color: var(--fg-faint);
  margin: 0 0 0.6rem;
  border: 0;
  padding: 0;
}

.toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc li {
  margin: 0.35rem 0;
}

.toc li.lv3 {
  padding-left: 0.9rem;
  font-size: 0.82rem;
}

.toc a {
  color: var(--fg-muted);
  text-decoration: none;
}

.toc a:hover {
  color: var(--accent);
  text-decoration: underline;
}

@media (max-width: 900px) {
  .toc {
    position: static;
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--border);
    padding: 1rem 0 0;
  }
}

/* ---------- 本文 ---------- */

.breadcrumb {
  font-size: 0.83rem;
  color: var(--fg-muted);
  margin-bottom: 1rem;
}

.breadcrumb a {
  color: var(--fg-muted);
}

article h1 {
  font-size: 1.85rem;
  line-height: 1.45;
  margin: 0 0 0.35rem;
  letter-spacing: -0.01em;
}

article .title-en {
  color: var(--fg-faint);
  font-size: 0.88rem;
  margin: 0 0 1.5rem;
}

article h2 {
  font-size: 1.32rem;
  margin: 2.8rem 0 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  line-height: 1.5;
}

article h3 {
  font-size: 1.1rem;
  margin: 2rem 0 0.75rem;
  line-height: 1.5;
}

article h4 {
  font-size: 1rem;
  margin: 1.6rem 0 0.6rem;
  color: var(--fg-muted);
}

article p {
  margin: 1rem 0;
}

article ul,
article ol {
  margin: 1rem 0;
  padding-left: 1.6rem;
}

article li {
  margin: 0.4rem 0;
}

article li > ul,
article li > ol {
  margin: 0.4rem 0;
}

article blockquote {
  margin: 1.25rem 0;
  padding: 0.2rem 0 0.2rem 1.1rem;
  border-left: 3px solid var(--border-strong);
  color: var(--fg-muted);
}

article hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

article img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

code {
  font-family: var(--mono);
  font-size: 0.875em;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  word-break: break-word;
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
  line-height: 1.65;
  font-size: 0.86rem;
}

pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
  word-break: normal;
  white-space: pre;
}

.table-scroll {
  overflow-x: auto;
  margin: 1.5rem 0;
}

table {
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 100%;
}

th,
td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.8rem;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--bg-soft);
  font-weight: 600;
  white-space: nowrap;
}

.footnotes {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--fg-muted);
}

/* ---------- 出典ボックス ---------- */

.source-box {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  margin: 0 0 2rem;
  font-size: 0.86rem;
  line-height: 1.75;
  color: var(--fg-muted);
}

.source-box dl {
  margin: 0;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.15rem 0.9rem;
}

.source-box dt {
  color: var(--fg-faint);
  white-space: nowrap;
}

.source-box dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.notice {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  padding: 0.8rem 1.1rem;
  margin: 1.5rem 0;
  font-size: 0.86rem;
  line-height: 1.75;
}

/* ---------- トップページ ---------- */

.hero {
  max-width: 60ch;
}

.hero h1 {
  font-size: 2rem;
  line-height: 1.4;
  margin: 0 0 0.5rem;
}

.hero .lead {
  color: var(--fg-muted);
  margin: 0 0 1.25rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  font-size: 0.85rem;
  color: var(--fg-muted);
  margin: 0 0 2rem;
  padding: 0.8rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.stats b {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

.search-row {
  margin: 0 0 2.5rem;
}

#filter {
  width: 100%;
  max-width: 26rem;
  padding: 0.6rem 0.8rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}

#filter:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.cat {
  margin: 0 0 2.5rem;
}

.cat > h2 {
  font-size: 1.15rem;
  margin: 0 0 0.2rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.cat > p {
  color: var(--fg-muted);
  font-size: 0.86rem;
  margin: 0.5rem 0 1rem;
}

.sheet-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr));
  gap: 0.5rem 1.5rem;
}

.sheet-list li {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.3rem 0;
  font-size: 0.94rem;
  min-width: 0;
}

.sheet-list .name {
  min-width: 0;
}

.sheet-list .en {
  display: block;
  font-size: 0.76rem;
  color: var(--fg-faint);
  line-height: 1.5;
}

.badge {
  flex: none;
  font-size: 0.68rem;
  line-height: 1.6;
  padding: 0 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--fg-faint);
  white-space: nowrap;
  transform: translateY(-1px);
}

.badge.ja {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

@media (prefers-color-scheme: dark) {
  .badge.ja {
    color: #14171c;
  }
}

.badge.dep {
  color: var(--fg-faint);
}

.no-hit {
  color: var(--fg-muted);
  font-size: 0.9rem;
}

/* ---------- ページ送り ---------- */

.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
}

.pager a {
  max-width: 45%;
}

/* ---------- フッタ ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
  font-size: 0.83rem;
  line-height: 1.8;
  color: var(--fg-muted);
}

.site-footer .inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.75rem 1.25rem;
}

.site-footer p {
  margin: 0.4rem 0;
}

.skip {
  position: absolute;
  left: -9999px;
}

.skip:focus {
  left: 0.5rem;
  top: 0.5rem;
  z-index: 10;
  background: var(--bg);
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}
