/* cpprefjp 風の 2 カラムレイアウト。左に階層ナビ、右に本文。 */

:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-code: #f5f6f8;
  --border: #e0e3e8;
  --border-strong: #c8ccd4;
  --text: #22262c;
  --text-soft: #5c6570;
  --link: #1256a0;
  --link-hover: #0b3d75;
  --accent: #2f6f4f;
  --mark: #fff3bf;
  --sidebar-width: 17rem;
  --content-width: 56rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --bg-soft: #1d2026;
    --bg-code: #1f232a;
    --border: #2c313a;
    --border-strong: #3a4149;
    --text: #dfe3e8;
    --text-soft: #9aa4b0;
    --link: #79b8ff;
    --link-hover: #a7d1ff;
    --accent: #7fc7a0;
    --mark: #4a4320;
  }
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP",
    "Yu Gothic UI", Meiryo, sans-serif;
  line-height: 1.75;
}

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }

/* ---- 上部バー ---- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1.25rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
}

.topbar-link { font-size: 0.85rem; color: var(--text-soft); }

.topbar-search { position: relative; flex: 1; max-width: 32rem; }

.topbar-search input {
  width: 100%;
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.topbar-search input:focus {
  outline: 2px solid var(--link);
  outline-offset: -1px;
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 60vh;
  margin: 0;
  padding: 0.25rem 0;
  overflow-y: auto;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 12%);
}

.search-results li a {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.3rem 0.7rem;
  color: var(--text);
}

.search-results li a:hover,
.search-results li.is-active a { background: var(--bg-soft); text-decoration: none; }

.search-results .result-kind {
  flex: none;
  min-width: 4.5rem;
  font-size: 0.7rem;
  color: var(--text-soft);
}

.search-results .result-name { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.search-results .result-header {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-soft);
}

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

.page {
  display: flex;
  align-items: flex-start;
  gap: 2rem;
  max-width: calc(var(--sidebar-width) + var(--content-width) + 6rem);
  margin: 0 auto;
  padding: 0 1.25rem;
}

.sidebar {
  position: sticky;
  top: 3.1rem;
  flex: none;
  width: var(--sidebar-width);
  max-height: calc(100vh - 3.1rem);
  padding: 1rem 0.5rem 3rem 0;
  overflow-y: auto;
  font-size: 0.85rem;
  border-right: 1px solid var(--border);
}

.sidebar-title { margin: 0 0 0.5rem; font-weight: 700; }

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

.sidebar summary {
  padding: 0.15rem 0.4rem;
  color: var(--text-soft);
  cursor: pointer;
  border-radius: 4px;
}

.sidebar summary:hover { background: var(--bg-soft); }

.sidebar-headers { padding-left: 0.7rem !important; }

.sidebar-headers > li > a {
  display: block;
  padding: 0.1rem 0.4rem;
  color: var(--text);
  border-radius: 4px;
  overflow-wrap: anywhere;
}

.sidebar-headers > li > a:hover { background: var(--bg-soft); text-decoration: none; }

.sidebar a.is-current {
  font-weight: 700;
  color: var(--link);
  background: var(--bg-soft);
}

.sidebar-entities {
  padding-left: 1.5rem !important;
  margin-bottom: 0.4rem !important;
  border-left: 2px solid var(--border);
}

.sidebar-entities a {
  display: block;
  padding: 0.05rem 0.4rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: var(--text-soft);
}

.content {
  flex: 1;
  min-width: 0;
  max-width: var(--content-width);
  padding: 1.25rem 0 4rem;
}

.footer {
  padding: 1.5rem 1.25rem;
  font-size: 0.8rem;
  color: var(--text-soft);
  text-align: center;
  border-top: 1px solid var(--border);
}

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

.breadcrumb {
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-soft);
}

.breadcrumb span[aria-hidden] { margin: 0 0.35rem; }

.content h1 {
  margin: 0 0 0.4rem;
  padding-bottom: 0.35rem;
  font-size: 1.85rem;
  line-height: 1.3;
  border-bottom: 2px solid var(--border-strong);
}

.content h2 {
  margin: 2.2rem 0 0.75rem;
  padding-bottom: 0.25rem;
  font-size: 1.3rem;
  border-bottom: 1px solid var(--border);
}

.content h3 { margin: 1.6rem 0 0.5rem; font-size: 1.08rem; }
.content h3 code { font-size: 1em; }
.content h4 { margin: 1.2rem 0 0.4rem; font-size: 0.98rem; }

.content > p:first-of-type em,
.page-meta {
  font-size: 0.82rem;
  color: var(--text-soft);
  font-style: normal;
}

.page-meta { margin: 0.2rem 0 1.2rem; }

.content p, .content ul, .content ol { margin: 0.6rem 0; }
.content li { margin: 0.15rem 0; }

code {
  padding: 0.1em 0.35em;
  font-family: ui-monospace, SFMono-Regular, Menlo, "Liberation Mono", monospace;
  font-size: 0.86em;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 4px;
}

pre {
  margin: 0.8rem 0;
  padding: 0.85rem 1rem;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.6;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 6px;
}

pre code {
  padding: 0;
  font-size: inherit;
  background: none;
  border: 0;
}

table {
  display: block;
  width: 100%;
  margin: 0.8rem 0;
  overflow-x: auto;
  font-size: 0.9rem;
  border-collapse: collapse;
}

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

th { background: var(--bg-soft); white-space: nowrap; }
td:first-child { white-space: nowrap; }
td code { white-space: nowrap; }

blockquote {
  margin: 0.8rem 0;
  padding: 0.2rem 1rem;
  color: var(--text-soft);
  border-left: 3px solid var(--border-strong);
}

/* ---- 付録（依存関係・実装） ---- */

.appendix { margin-top: 3rem; }

.appendix details,
.verification-list {
  margin: 0.5rem 0;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.appendix summary,
.verification-list summary {
  padding: 0.5rem 0.8rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.appendix details[open] summary,
.verification-list[open] summary { border-bottom: 1px solid var(--border); }

.appendix ul,
.verification-list ul {
  margin: 0;
  padding: 0.6rem 0.9rem;
  list-style: none;
}

.appendix li,
.verification-list li {
  display: flex;
  gap: 0.4rem;
  align-items: baseline;
  font-size: 0.85rem;
}

.appendix li code,
.verification-list li code {
  font-size: 0.75rem;
  color: var(--text-soft);
  background: none;
  border: 0;
}

.appendix pre { margin: 0; border: 0; border-radius: 0; }
.appendix h3 { margin: 0.6rem 0.9rem 0; }
.verification-list h3 { margin: 0.8rem 0.9rem 0; font-size: 0.9rem; }

.verification-icon { font-size: 0.8em; }

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

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.category-card {
  padding: 0.75rem 1rem 1rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.category-card h2 {
  margin: 0 0 0.4rem;
  padding: 0;
  font-size: 1rem;
  color: var(--accent);
  border: 0;
}

.category-card ul { margin: 0; padding: 0; list-style: none; }
.category-card li { display: flex; gap: 0.35rem; align-items: baseline; font-size: 0.85rem; }
.category-card small {
  overflow: hidden;
  color: var(--text-soft);
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .page { flex-direction: column; gap: 0; }
  .sidebar {
    position: static;
    width: 100%;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .content { max-width: 100%; }
}

/* ---- rouge（コードハイライト） ---- */

.highlight .c, .highlight .cm, .highlight .c1, .highlight .cs { color: #6a737d; font-style: italic; }
.highlight .cp { color: #8250df; }
.highlight .k, .highlight .kd, .highlight .kn, .highlight .kp, .highlight .kr, .highlight .kt { color: #cf222e; }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sc { color: #0a3069; }
.highlight .m, .highlight .mi, .highlight .mf, .highlight .mh { color: #0550ae; }
.highlight .n, .highlight .nx { color: inherit; }
.highlight .nf, .highlight .nd { color: #6639ba; }
.highlight .nc, .highlight .nn { color: #953800; }
.highlight .o, .highlight .ow { color: #cf222e; }
.highlight .err { color: inherit; background: none; }

@media (prefers-color-scheme: dark) {
  .highlight .c, .highlight .cm, .highlight .c1, .highlight .cs { color: #8b949e; }
  .highlight .cp { color: #d2a8ff; }
  .highlight .k, .highlight .kd, .highlight .kn, .highlight .kp, .highlight .kr, .highlight .kt { color: #ff7b72; }
  .highlight .s, .highlight .s1, .highlight .s2, .highlight .sc { color: #a5d6ff; }
  .highlight .m, .highlight .mi, .highlight .mf, .highlight .mh { color: #79c0ff; }
  .highlight .nf, .highlight .nd { color: #d2a8ff; }
  .highlight .nc, .highlight .nn { color: #ffa657; }
  .highlight .o, .highlight .ow { color: #ff7b72; }
}
