:root {
  --page: #ffffff;
  --chrome: #f8f9fa;
  --chrome-2: #eaecf0;
  --border: #a2a9b1;
  --border-soft: #c8ccd1;
  --text: #202122;
  --muted: #54595d;
  --link: #3366cc;
  --visited: #795cb2;
  --missing: #ba0000;
  --tab-active-border: #3680b0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: -apple-system, 'Helvetica Neue', Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

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

a:visited {
  color: var(--visited);
}

a:hover {
  text-decoration: underline;
}

/* ── Layout ─────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 280px;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────── */

.sidebar {
  background: var(--chrome);
  border-right: 1px solid var(--border-soft);
  padding: 0 0 24px;
  font-size: 13px;
}

.brand {
  display: block;
  text-align: center;
  padding: 16px 12px 10px;
  border-bottom: 1px solid var(--border-soft);
  text-decoration: none;
  color: var(--text);
}

.brand-logo {
  display: block;
  margin: 0 auto 6px;
  width: 72px;
  height: 72px;
}

.brand-name {
  display: block;
  font-family: 'Linux Libertine', Georgia, 'Times New Roman', serif;
  font-size: 17px;
  line-height: 1.2;
  color: var(--text);
}

.brand-tagline {
  display: block;
  font-family: 'Linux Libertine', Georgia, 'Times New Roman', serif;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
}

.search input {
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  font: inherit;
  padding: 5px 6px;
  width: 100%;
  background: var(--page);
}

.search input:focus {
  outline: 2px solid var(--tab-active-border);
  outline-offset: -1px;
  border-color: var(--tab-active-border);
}

.sidebar-section {
  padding: 0 0 8px;
}

.sidebar-section-label {
  background: var(--chrome-2);
  border-top: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 0.04em;
  padding: 5px 12px;
  text-transform: uppercase;
  margin-bottom: 4px;
}

nav a,
.page-list a,
.compact-list a {
  display: block;
  padding: 2px 12px;
  color: var(--link);
}

nav a:hover,
.page-list a:hover,
.compact-list a:hover {
  background: var(--chrome-2);
  text-decoration: none;
}

/* ── Tab bar ─────────────────────────────────────────── */

.tab-bar {
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  background: linear-gradient(to bottom, var(--chrome) 0%, var(--page) 100%);
  padding: 0 24px;
  margin: 0 0 20px;
  min-height: 40px;
}

.tab-bar-left,
.tab-bar-right {
  display: flex;
  align-items: flex-end;
  gap: 0;
}

.tab {
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 2px 2px 0 0;
  color: var(--link);
  cursor: default;
  display: inline-block;
  font-size: 13px;
  margin-bottom: -1px;
  padding: 7px 13px;
  position: relative;
  text-decoration: none;
  white-space: nowrap;
  background: transparent;
  user-select: none;
}

.tab:hover {
  background: var(--chrome-2);
  text-decoration: none;
}

.tab.active {
  background: var(--page);
  border-color: var(--border);
  border-bottom-color: var(--page);
  border-top: 3px solid var(--tab-active-border);
  color: var(--text);
  padding-top: 5px;
}

/* ── Article ─────────────────────────────────────────── */

.article-shell {
  min-width: 0;
  padding: 0 0 40px;
}

.article {
  max-width: 960px;
  padding: 0 24px;
}

.article h1 {
  border-bottom: 1px solid var(--border);
  font-family: 'Linux Libertine', Georgia, 'Times New Roman', serif;
  font-size: 2em;
  font-weight: normal;
  line-height: 1.3;
  margin: 0 0 16px;
  padding-bottom: 3px;
}

.article h2 {
  border-bottom: 1px solid var(--border);
  font-family: 'Linux Libertine', Georgia, 'Times New Roman', serif;
  font-size: 1.5em;
  font-weight: normal;
  margin: 28px 0 8px;
  padding-bottom: 2px;
}

.article h3 {
  font-size: 1.15em;
  font-weight: bold;
  margin: 18px 0 4px;
}

.article h4 {
  font-size: 1em;
  font-weight: bold;
  margin: 12px 0 2px;
}

.article p {
  margin: 0.5em 0 0.8em;
}

.article ul,
.article ol {
  margin: 0.3em 0 0.8em 1.6em;
  padding: 0;
}

.article li {
  margin: 2px 0;
}

.article code {
  background: var(--chrome);
  border: 1px solid var(--chrome-2);
  border-radius: 2px;
  font-size: 13px;
  padding: 1px 4px;
}

.article pre {
  background: var(--chrome);
  border: 1px solid var(--border-soft);
  overflow: auto;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
}

.article pre code {
  background: none;
  border: none;
  padding: 0;
}

.article blockquote {
  border-left: 3px solid var(--border);
  color: var(--muted);
  margin: 0.8em 0 0.8em 24px;
  padding: 2px 12px;
}

.article table {
  border-collapse: collapse;
  margin: 1em 0;
}

.article th,
.article td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.article th {
  background: var(--chrome-2);
}

.missing-link {
  color: var(--missing);
}

/* ── Table of Contents ───────────────────────────────── */

.toc {
  background: var(--chrome);
  border: 1px solid var(--border);
  display: table;
  font-size: 13px;
  margin: 0 0 16px;
  padding: 0;
  min-width: 200px;
  max-width: 320px;
}

.toc-title {
  background: var(--chrome-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px;
  font-weight: bold;
  font-size: 13px;
}

.toc-toggle {
  color: var(--link);
  cursor: pointer;
  font-size: 12px;
  font-weight: normal;
  margin-left: 8px;
  user-select: none;
}

.toc-toggle:hover {
  text-decoration: underline;
}

.toc-body {
  padding: 6px 12px 8px 8px;
}

.toc ol {
  list-style: none;
  margin: 0;
  padding: 0 0 0 12px;
  counter-reset: toc-h2;
}

.toc > .toc-body > ol {
  padding-left: 4px;
}

.toc li {
  margin: 3px 0;
  line-height: 1.4;
}

.toc a {
  color: var(--link);
  font-size: 13px;
}

.toc a:hover {
  text-decoration: underline;
}

.toc .toc-num {
  color: var(--muted);
  margin-right: 4px;
}

.toc ol ol {
  margin-top: 3px;
  padding-left: 16px;
}

/* ── Search results ──────────────────────────────────── */

.search-results {
  background: var(--chrome);
  border: 1px solid var(--border);
  margin: 0 24px 18px;
  max-width: 960px;
  padding: 12px;
}

.search-results h2 {
  border-bottom: 1px solid var(--border);
  font-family: 'Linux Libertine', Georgia, 'Times New Roman', serif;
  font-size: 1.3em;
  font-weight: normal;
  margin: 0 0 8px;
}

.result {
  border-bottom: 1px solid var(--border-soft);
  padding: 8px 0;
}

.result:last-child {
  border-bottom: 0;
}

.result a {
  font-weight: bold;
}

.result p,
.empty {
  color: var(--muted);
  margin: 2px 0;
}

/* ── Page footer ─────────────────────────────────────── */

.page-footer {
  border-top: 1px solid var(--border-soft);
  clear: both;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  margin-top: 32px;
  padding: 10px 0 0;
}

/* ── Context panel (right column) ────────────────────── */

.context {
  background: var(--chrome);
  border-left: 1px solid var(--border-soft);
  padding: 0 14px 24px;
  font-size: 13px;
}

.context h2 {
  border-bottom: 1px solid var(--border-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 0.04em;
  margin: 16px 0 6px;
  padding-bottom: 2px;
  text-transform: uppercase;
}

dl {
  margin: 0;
}

dt {
  color: var(--muted);
  font-weight: bold;
  font-size: 12px;
  margin-top: 8px;
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 12px;
}

canvas {
  background: #fff;
  border: 1px solid var(--border);
  height: auto;
  max-width: 100%;
  margin-top: 4px;
}

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 1100px) {
  .shell {
    grid-template-columns: 200px minmax(0, 1fr);
  }

  .context {
    display: none;
  }
}

@media (max-width: 720px) {
  .shell {
    display: block;
  }

  .sidebar {
    border-bottom: 1px solid var(--border-soft);
    border-right: 0;
  }

  .brand {
    padding: 10px 12px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .brand-logo {
    width: 40px;
    height: 40px;
    margin: 0;
  }

  .tab-bar {
    padding: 0 14px;
  }

  .article {
    padding: 0 14px;
  }

  .search-results {
    margin: 0 14px 16px;
  }
}
