/* ══════════════════════════════════════════════════════════════
   Linked.Archi Publications

   Styled to match the MkDocs Material site at meta.linked.archi/docs.
   Token names mirror Material's own (--md-*) so the two are directly
   comparable, and the palette is the one in
   linked-archi-meta/doc/overrides/assets/stylesheets/extra.css:

     primary blue  #1565c0   header, links
     accent teal   #00baa3   hover, focus
     logo red      #d55342   secondary accent
     logo gold     #efc945   dark-mode accent

   One deliberate departure: Material sets html{font-size:125%} and
   then scales everything down with em. This sheet keeps the root at
   100% and expresses the same ratios, because every rem in this
   project's templates and inline scripts would otherwise grow by a
   quarter. The rendered sizes match Material at default zoom.
   ══════════════════════════════════════════════════════════════ */

/* ── Tokens: light ──────────────────────────────────────────── */
:root,
[data-md-color-scheme="default"] {
  --md-primary-fg-color:        #1565c0;
  --md-primary-fg-color--light: #4fc3f7;
  --md-primary-fg-color--dark:  #0d47a1;
  --md-primary-bg-color:        #ffffff;

  --md-accent-fg-color:         #00baa3;
  --md-accent-fg-color--transparent: rgba(0, 186, 163, 0.1);

  --md-secondary-fg-color:      #d55342;

  --md-default-fg-color:          rgba(0, 0, 0, 0.87);
  --md-default-fg-color--light:   rgba(0, 0, 0, 0.54);
  --md-default-fg-color--lighter: rgba(0, 0, 0, 0.32);
  --md-default-fg-color--lightest: rgba(0, 0, 0, 0.07);
  --md-default-bg-color:          #ffffff;
  --md-default-bg-color--light:   #fafafa;

  --md-code-fg-color: #36464e;
  --md-code-bg-color: #f5f5f5;

  --md-typeset-a-color:     var(--md-primary-fg-color);
  --md-typeset-mark-color:  rgba(255, 235, 59, 0.5);
  --md-typeset-table-color: rgba(0, 0, 0, 0.12);

  --md-footer-bg-color:      rgba(0, 0, 0, 0.87);
  --md-footer-bg-color--dark: rgba(0, 0, 0, 0.32);
  --md-footer-fg-color:       #ffffff;
  --md-footer-fg-color--light: rgba(255, 255, 255, 0.7);

  --md-shadow-z1: 0 0.2rem 0.5rem rgba(0, 0, 0, 0.05), 0 0 0.05rem rgba(0, 0, 0, 0.1);
  --md-shadow-z2: 0 0.2rem 0.5rem rgba(0, 0, 0, 0.1), 0 0 0.05rem rgba(0, 0, 0, 0.25);
  --md-shadow-z3: 0 0.2rem 0.5rem rgba(0, 0, 0, 0.2), 0 0 0.05rem rgba(0, 0, 0, 0.35);

  /* Graph palettes, read by the D3 code so the legend, the page graph
     and the sidebar graphs cannot drift apart. */
  --graph-article:    #1565c0;
  --graph-concept:    #00baa3;
  --graph-section:    #7e57c2;
  --graph-subsection: #9575cd;
  --graph-tag:        #efc945;
  --graph-external:   #d55342;
  --graph-entity:     #00838f;
  --graph-link:       rgba(0, 0, 0, 0.32);
  --graph-node-stroke: #ffffff;
  --graph-bg:         #fafafa;

  /* Material's sidebars are a fixed 12.1rem at its 125% root, i.e. 242px,
     inside a 61rem grid. These are wider and elastic instead: the prose
     track is capped at a readable measure and the rails absorb whatever
     the viewport has spare, between the floor and the ceiling below. That
     keeps the panels close to the screen edges on a wide display without
     letting a table of contents grow to 400px.

     The two gutters are what separate the rails from the prose, and they
     stay fixed at every width: 1rem inside the prose column plus 2rem
     inside the rail, so 48px of clear space on each side. */
  --md-nav-width: 18rem;
  --md-aside-width: 18rem;
  --md-rail-content-max: 28rem;
  --md-grid-width: 118rem;
  --md-content-width: 46rem;
  --md-rail-gutter: 2rem;
  --md-prose-gutter: 1rem;
}

/* ── Tokens: dark (Material's "slate") ──────────────────────── */
[data-md-color-scheme="slate"] {
  --md-primary-fg-color:        #1565c0;
  --md-primary-fg-color--light: #5e92f3;
  --md-primary-fg-color--dark:  #003c8f;
  --md-primary-bg-color:        #ffffff;

  --md-accent-fg-color:         #4dd9c5;
  --md-accent-fg-color--transparent: rgba(77, 217, 197, 0.1);

  --md-secondary-fg-color:      #ef8a7c;

  --md-default-fg-color:          rgba(255, 255, 255, 0.9);
  --md-default-fg-color--light:   rgba(255, 255, 255, 0.62);
  --md-default-fg-color--lighter: rgba(255, 255, 255, 0.32);
  --md-default-fg-color--lightest: rgba(255, 255, 255, 0.12);
  --md-default-bg-color:          #1f2129;
  --md-default-bg-color--light:   #262a35;

  --md-code-fg-color: #d1d5db;
  --md-code-bg-color: #171a21;

  --md-typeset-a-color:     #7eb8f0;
  --md-typeset-mark-color:  rgba(239, 201, 69, 0.35);
  --md-typeset-table-color: rgba(255, 255, 255, 0.12);

  --md-footer-bg-color:      #14161b;
  --md-footer-bg-color--dark: #0e1014;

  --md-shadow-z1: 0 0.2rem 0.5rem rgba(0, 0, 0, 0.2), 0 0 0.05rem rgba(0, 0, 0, 0.35);
  --md-shadow-z2: 0 0.2rem 0.5rem rgba(0, 0, 0, 0.3), 0 0 0.05rem rgba(0, 0, 0, 0.45);
  --md-shadow-z3: 0 0.2rem 0.5rem rgba(0, 0, 0, 0.4), 0 0 0.05rem rgba(0, 0, 0, 0.55);

  --graph-article:    #64b5f6;
  --graph-concept:    #4dd9c5;
  --graph-section:    #b39ddb;
  --graph-subsection: #9575cd;
  --graph-tag:        #efc945;
  --graph-external:   #ef8a7c;
  --graph-entity:     #4dd0e1;
  --graph-link:       rgba(255, 255, 255, 0.32);
  --graph-node-stroke: #1f2129;
  --graph-bg:         #191b21;
}

/* ── Reset ──────────────────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

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

body {
  font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--md-default-fg-color);
  background: var(--md-default-bg-color);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ══ Typography ════════════════════════════════════════════════
   Material's type scale: h1 and h2 in Roboto Light, tightened
   letter-spacing, and the muted heading colour that gives the docs
   their quiet look.
   ═══════════════════════════════════════════════════════════════ */

h1, h2, h3, h4, h5, h6 {
  color: var(--md-default-fg-color);
  font-weight: 400;
}

h1 {
  font-size: 2em;
  line-height: 1.3;
  font-weight: 300;
  letter-spacing: -0.01em;
  color: var(--md-default-fg-color--light);
  margin: 0 0 1.25em;
}

h2 {
  font-size: 1.5625em;
  line-height: 1.4;
  font-weight: 300;
  letter-spacing: -0.01em;
  margin: 1.6em 0 0.64em;
}

h3 {
  font-size: 1.25em;
  line-height: 1.5;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin: 1.6em 0 0.8em;
}

h4 {
  font-size: 1em;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 1em 0;
}

h5, h6 {
  font-size: 0.8em;
  font-weight: 700;
  color: var(--md-default-fg-color--light);
  margin: 1.25em 0;
}

h5 { text-transform: uppercase; }

p, ul, ol, dl, blockquote, pre, table, figure {
  margin: 1em 0;
}

ul, ol { margin-left: 0.625em; padding-left: 1.25em; }
li { margin-bottom: 0.5em; }
li > ul, li > ol { margin: 0.5em 0; }

a {
  color: var(--md-typeset-a-color);
  text-decoration: none;
  word-break: break-word;
  transition: color 125ms;
}

a:hover,
a:focus {
  color: var(--md-accent-fg-color);
}

a:focus-visible {
  outline: 2px solid var(--md-accent-fg-color);
  outline-offset: 2px;
  border-radius: 0.1rem;
}

strong, b { font-weight: 700; }

hr {
  border: 0;
  border-bottom: 0.05rem solid var(--md-default-fg-color--lightest);
  margin: 1.5em 0;
}

blockquote {
  border-left: 0.2rem solid var(--md-default-fg-color--lighter);
  color: var(--md-default-fg-color--light);
  padding-left: 0.9em;
  margin-left: 0;
}

mark {
  background: var(--md-typeset-mark-color);
  color: inherit;
  padding: 0 0.1em;
  border-radius: 0.1rem;
}

img { max-width: 100%; height: auto; }

/* ── Image lightbox ─────────────────────────────────────────────
   GLightbox, as on meta.linked.archi; see src/layouts/lightbox-script.njk.
   The overlay rule is meta's extra.css one. D2's SVGs declare only a viewBox,
   so without it the enlarged copy falls back to a small default size. */
.main-content a.glightbox img { cursor: zoom-in; }
.glightbox-clean .gslide-image img[src$=".svg"] {
  width: 90vw !important;
  max-width: 90vw !important;
  height: auto !important;
  max-height: 90vh !important;
  object-fit: contain;
}

/* ── Code ───────────────────────────────────────────────────── */
code, kbd, pre, samp {
  font-family: "Roboto Mono", SFMono-Regular, Consolas, Menlo, monospace;
  font-variant-ligatures: none;
}

code {
  background: var(--md-code-bg-color);
  color: var(--md-code-fg-color);
  font-size: 0.85em;
  padding: 0 0.2941176471em;
  border-radius: 0.1rem;
  word-break: break-word;
  box-decoration-break: clone;
}

pre {
  background: var(--md-code-bg-color);
  border-radius: 0.1rem;
  font-size: 0.85em;
  line-height: 1.4;
  overflow: auto;
  margin: 1em 0;
  padding: 0.7720588235em 1.1764705882em;
}

pre > code {
  background: transparent;
  padding: 0;
  font-size: 1em;
  word-break: normal;
  display: block;
}

a code { color: currentColor; }

/* ── Tables ─────────────────────────────────────────────────── */
table {
  background: var(--md-default-bg-color);
  border: 0.05rem solid var(--md-typeset-table-color);
  border-radius: 0.1rem;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85em;
  overflow: hidden;
  width: 100%;
}

th {
  background: var(--md-default-bg-color);
  color: var(--md-default-fg-color);
  font-weight: 700;
  text-align: left;
  vertical-align: top;
  padding: 0.9375em 1.25em;
}

td {
  border-top: 0.05rem solid var(--md-typeset-table-color);
  padding: 0.9375em 1.25em;
  vertical-align: top;
}

tbody tr:hover { background: var(--md-default-fg-color--lightest); }

.table-wrap { overflow-x: auto; margin: 1em 0; }

/* ══ Header ════════════════════════════════════════════════════
   Material's header: solid primary bar, white type, shadow once the
   page scrolls under it.
   ═══════════════════════════════════════════════════════════════ */

.md-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--md-primary-fg-color);
  color: var(--md-primary-bg-color);
  box-shadow: none;
  transition: box-shadow 250ms, background 125ms;
}

.md-header--shadow { box-shadow: var(--md-shadow-z2); }

.nav-content {
  max-width: var(--md-grid-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  height: 3rem;
  padding: 0 0.8rem;
}

.home-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--md-primary-bg-color);
  font-size: 1.125rem;
  font-weight: 400;
  line-height: 1.2;
  padding: 0.35rem 0.4rem;
  border-radius: 0.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-link:hover,
.home-link:focus {
  color: var(--md-primary-bg-color);
  opacity: 0.75;
}

.site-logo {
  height: 1.2rem;
  width: 1.2rem;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.nav-menu {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.1rem;
}

.nav-link {
  color: var(--md-primary-bg-color);
  font-size: 0.8rem;
  font-weight: 400;
  padding: 0.4rem 0.6rem;
  border-radius: 0.1rem;
  white-space: nowrap;
  opacity: 0.85;
  transition: opacity 125ms, background 125ms;
}

.nav-link:hover,
.nav-link:focus,
.nav-link[aria-current="page"] {
  color: var(--md-primary-bg-color);
  background: rgba(255, 255, 255, 0.12);
  opacity: 1;
}

.nav-link[aria-current="page"] { font-weight: 500; }

.nav-link-external { opacity: 0.7; }

.nav-divider {
  width: 1px;
  height: 1.2rem;
  background: rgba(255, 255, 255, 0.3);
  margin: 0 0.3rem;
}

.nav-toggle,
.scheme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  color: var(--md-primary-bg-color);
  font-size: 1.1rem;
  line-height: 1;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  cursor: pointer;
  transition: background 125ms;
}

.nav-toggle:hover,
.scheme-toggle:hover { background: rgba(255, 255, 255, 0.12); }

.nav-toggle { display: none; }

/* ══ Layout ════════════════════════════════════════════════════ */

main {
  flex: 1 0 auto;
  width: 100%;
}

.page {
  max-width: var(--md-grid-width);
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.page--narrow { max-width: 52rem; }

.page__title {
  margin-bottom: 0.4em;
}

.page__lede {
  font-size: 1.05em;
  color: var(--md-default-fg-color--light);
  margin: 0 0 2rem;
  max-width: 44rem;
}

.section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--md-default-fg-color--light);
  margin: 2.5rem 0 1rem;
}

.listing-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  align-items: center;
  justify-content: space-between;
  margin: 2.5rem 0 0.5rem;
  border-bottom: 0.05rem solid var(--md-default-fg-color--lightest);
  padding-bottom: 0.6rem;
}

.listing-head h2 { margin: 0; }

/* ── Utilities ──────────────────────────────────────────────── */
.is-hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.layout-container {
  display: block;
  max-width: var(--md-grid-width);
  margin: 0 auto;
  padding: 0 1rem;
}

.main-content {
  background: var(--md-default-bg-color);
  padding: 1.2rem 0 3rem;
  max-width: var(--md-content-width);
  margin: 0 auto;
  min-width: 0;
}

/* ── Sidebars ───────────────────────────────────────────────── */
.toc-sidebar,
.refs-sidebar {
  padding: 1.2rem 0;
  border-top: 0.05rem solid var(--md-default-fg-color--lightest);
}

.toc-sidebar.hidden .toc-content,
.refs-sidebar.hidden .refs-content { display: none; }

.toc-content,
.refs-content { margin-top: 0.6rem; }

.toc-content h3,
.refs-content h3,
.sidebar-heading {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--md-default-fg-color--light);
  margin: 1.5rem 0 0.5rem;
  line-height: 1.4;
}

.toc-content > h3:first-child,
.refs-content > h3:first-child { margin-top: 0; }

.sidebar-heading--toggle { cursor: pointer; user-select: none; }
.sidebar-heading--toggle:hover { color: var(--md-accent-fg-color); }

#toc { border-left: 0.05rem solid var(--md-default-fg-color--lightest); }

#toc a {
  display: block;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--md-default-fg-color--light);
  padding: 0.35rem 0.6rem;
  border-left: 0.1rem solid transparent;
  margin-left: -0.05rem;
  transition: color 125ms, border-color 125ms;
}

#toc a:hover { color: var(--md-accent-fg-color); }

#toc a.h3 { padding-left: 1.4rem; font-size: 0.75rem; }

#toc a.active {
  color: var(--md-primary-fg-color);
  border-left-color: var(--md-primary-fg-color);
  font-weight: 500;
  background: transparent;
}

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

.sidebar-item {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  padding: 0.35rem 0;
  border-bottom: 0.05rem solid var(--md-default-fg-color--lightest);
  font-size: 0.8rem;
}

.sidebar-item:last-child { border-bottom: 0; }
.sidebar-item__link { flex: 1; min-width: 0; }
.sidebar-item__link--capitalize { text-transform: capitalize; }

.sidebar-item__primary { display: block; }

.sidebar-item__sub {
  display: block;
  font-size: 0.7rem;
  color: var(--md-default-fg-color--lighter);
}

.sidebar-heading__link {
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  margin-left: 0.4rem;
}

/* Marks whatever a sidebar entry points at, for a couple of seconds. */
.flash {
  background: var(--md-typeset-mark-color);
  transition: background 400ms;
}

.sidebar-item__count {
  font-size: 0.7rem;
  color: var(--md-default-fg-color--lighter);
  min-width: 1.25rem;
  text-align: right;
}

.sidebar-item__rank {
  font-size: 0.7rem;
  color: var(--md-primary-fg-color);
}

.sidebar-note {
  font-size: 0.8rem;
  color: var(--md-default-fg-color--lighter);
  padding: 0.35rem 0;
}

.sidebar-note--warn { color: var(--md-secondary-fg-color); }

.icon-btn {
  background: transparent;
  border: 0.05rem solid var(--md-default-fg-color--lightest);
  border-radius: 0.1rem;
  color: var(--md-default-fg-color--light);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
  transition: background 125ms, color 125ms;
}

.icon-btn:hover {
  background: var(--md-accent-fg-color--transparent);
  color: var(--md-accent-fg-color);
}

.collapsed { display: none; }

/* ── Rail toggles ───────────────────────────────────────────── */
.toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  background: transparent;
  color: var(--md-default-fg-color--light);
  border: 0.05rem solid var(--md-default-fg-color--lightest);
  border-radius: 0.1rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.45rem 0.6rem;
  transition: background 125ms, color 125ms, border-color 125ms;
}

.toggle-btn:hover {
  background: var(--md-accent-fg-color--transparent);
  color: var(--md-accent-fg-color);
  border-color: var(--md-accent-fg-color);
}

/* ── Heading anchors ────────────────────────────────────────── */
.main-content h2,
.main-content h3 { position: relative; }

.headerlink {
  position: absolute;
  left: -0.9em;
  opacity: 0;
  color: var(--md-default-fg-color--lighter);
  font-weight: 400;
  transition: opacity 125ms, color 125ms;
}

.headerlink-icon { font-size: 0.85em; }

h2:hover .headerlink,
h3:hover .headerlink,
.headerlink:focus { opacity: 1; }

.headerlink:hover { color: var(--md-accent-fg-color); }

/* ── Transclusion: Material's admonition ────────────────────── */
.transcluded {
  background: var(--md-default-bg-color);
  border: 0.05rem solid var(--md-accent-fg-color);
  border-left-width: 0.2rem;
  border-radius: 0.1rem;
  box-shadow: var(--md-shadow-z1);
  font-size: 0.95em;
  margin: 1.5625em 0;
  padding: 0.6rem 0.9rem;
}

.transcluded > :first-child { margin-top: 0; }
.transcluded > :last-child { margin-bottom: 0; }

.transcluded__source {
  font-size: 0.8em;
  margin-left: 0.5rem;
  white-space: nowrap;
}

/* ── Article title with a subtitle (frontmatter `subtitle:`) ── */
.doc-title { margin: 0 0 1.25em; }
.doc-title h1 { margin-bottom: 0.25em; }
.doc-title__subtitle {
  margin: 0;
  font-size: 1.25em;
  line-height: 1.4;
  font-weight: 300;
  color: var(--md-default-fg-color--light);
}

/* ── Article and concept meta panel ─────────────────────────── */
.doc-meta {
  border-left: 0.2rem solid var(--md-primary-fg-color);
  background: var(--md-default-bg-color--light);
  border-radius: 0.1rem;
  padding: 0.8rem 1rem;
  margin: 1.5em 0;
}

.doc-meta__row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
  align-items: center;
  font-size: 0.85rem;
  color: var(--md-default-fg-color--light);
}

.doc-meta__summary {
  margin: 0.6rem 0 0;
  font-style: italic;
  color: var(--md-default-fg-color);
}

.doc-meta__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

/* ── Chips, tags, badges ────────────────────────────────────── */
.chip,
.tag {
  display: inline-block;
  background: var(--md-default-bg-color--light);
  border: 0.05rem solid var(--md-default-fg-color--lightest);
  border-radius: 1rem;
  color: var(--md-default-fg-color--light);
  font-size: 0.7rem;
  line-height: 1.6;
  padding: 0.05rem 0.55rem;
  white-space: nowrap;
}

.chip--lg { font-size: 0.8rem; padding: 0.2rem 0.7rem; }

a.tag:hover,
a.chip:hover {
  border-color: var(--md-accent-fg-color);
  color: var(--md-accent-fg-color);
}

.badge {
  display: inline-block;
  background: var(--md-default-fg-color--lightest);
  border-radius: 0.1rem;
  color: var(--md-default-fg-color--light);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.1rem 0.35rem;
  white-space: nowrap;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--md-primary-fg-color);
  color: #fff;
  border: 0.05rem solid transparent;
  border-radius: 0.1rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.5rem 1rem;
  transition: background 125ms, box-shadow 125ms;
}

.btn:hover,
.btn:focus {
  background: var(--md-accent-fg-color);
  color: #fff;
  box-shadow: var(--md-shadow-z1);
}

.btn--lg { font-size: 0.8rem; padding: 0.65rem 1.4rem; }

.btn--ghost {
  background: transparent;
  color: var(--md-default-fg-color--light);
  border-color: var(--md-default-fg-color--lightest);
}

.btn--ghost:hover {
  background: var(--md-accent-fg-color--transparent);
  color: var(--md-accent-fg-color);
  border-color: var(--md-accent-fg-color);
  box-shadow: none;
}

/* Segmented filter and view controls */
.control-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin: 1rem 0 1.5rem;
}

.control-bar__divider {
  width: 1px;
  align-self: stretch;
  background: var(--md-default-fg-color--lightest);
  margin: 0 0.3rem;
}

.control-bar__spacer { flex: 1 1 auto; }

.control-bar__label {
  font-size: 0.75rem;
  color: var(--md-default-fg-color--light);
}

.select {
  background: var(--md-default-bg-color);
  border: 0.05rem solid var(--md-default-fg-color--lightest);
  border-radius: 0.1rem;
  color: var(--md-default-fg-color);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.75rem;
  padding: 0.3rem 0.5rem;
}

.select:focus {
  outline: none;
  border-color: var(--md-accent-fg-color);
}

.filter-btn,
.tag-btn {
  background: transparent;
  border: 0.05rem solid var(--md-default-fg-color--lightest);
  border-radius: 1rem;
  color: var(--md-default-fg-color--light);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.75rem;
  padding: 0.3rem 0.8rem;
  transition: background 125ms, color 125ms, border-color 125ms;
}

.filter-btn:hover,
.tag-btn:hover {
  border-color: var(--md-accent-fg-color);
  color: var(--md-accent-fg-color);
}

.filter-btn.selected,
.filter-btn[aria-pressed="true"],
.tag-btn.selected {
  background: var(--md-primary-fg-color);
  border-color: var(--md-primary-fg-color);
  color: #fff;
}

.search-box {
  width: 100%;
  background: var(--md-default-bg-color);
  border: 0.05rem solid var(--md-default-fg-color--lightest);
  border-radius: 0.1rem;
  color: var(--md-default-fg-color);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.6rem 0.8rem;
  margin: 1rem 0;
  transition: border-color 125ms, box-shadow 125ms;
}

.search-box::placeholder { color: var(--md-default-fg-color--lighter); }

.search-box:focus {
  outline: none;
  border-color: var(--md-accent-fg-color);
  box-shadow: 0 0 0 0.1rem var(--md-accent-fg-color--transparent);
}

.search-box--inline { width: auto; min-width: 12rem; margin: 0; }

/* ── Cards and listings ─────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.grid--tight { grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }

.list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 1.5rem 0;
}

.card {
  background: var(--md-default-bg-color);
  border: 0.05rem solid var(--md-default-fg-color--lightest);
  border-radius: 0.1rem;
  box-shadow: var(--md-shadow-z1);
  padding: 1rem 1.1rem;
  transition: box-shadow 125ms, border-color 125ms;
  height: 100%;
}

a > .card { color: var(--md-default-fg-color); }

.card:hover {
  border-color: var(--md-accent-fg-color);
  box-shadow: var(--md-shadow-z2);
}

.card__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}

.card-title,
.card h3 {
  font-size: 1.05rem;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0;
  margin: 0;
  color: var(--md-default-fg-color);
}

.card:hover .card-title,
.card:hover h3 { color: var(--md-primary-fg-color); }

.card-meta,
.card .meta {
  font-size: 0.75rem;
  color: var(--md-default-fg-color--lighter);
  margin: 0.3rem 0;
}

.card-desc,
.card p {
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--md-default-fg-color--light);
  margin: 0.4rem 0 0;
}

.card-tags,
.card .tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.8rem;
}

.list .card { display: flex; align-items: flex-start; gap: 1rem; }
.list .card-content { flex: 1; min-width: 0; }

.card-link { display: block; color: inherit; height: 100%; }
.card-link:hover { color: inherit; }

/* Feature tiles (about page navigation) */
.tile {
  display: block;
  background: var(--md-default-bg-color);
  border: 0.05rem solid var(--md-default-fg-color--lightest);
  border-radius: 0.1rem;
  box-shadow: var(--md-shadow-z1);
  color: var(--md-default-fg-color);
  padding: 1.1rem;
  text-align: center;
  transition: box-shadow 125ms, border-color 125ms;
}

.tile:hover {
  border-color: var(--md-accent-fg-color);
  box-shadow: var(--md-shadow-z2);
  color: var(--md-default-fg-color);
}

.tile__icon { font-size: 1.6rem; line-height: 1; }
.tile__title { font-weight: 500; margin: 0.4rem 0 0.2rem; }
.tile__desc { font-size: 0.8rem; color: var(--md-default-fg-color--light); }

/* Typed reference cards (about page) */
.type-card {
  background: var(--md-default-bg-color);
  border: 0.05rem solid var(--md-default-fg-color--lightest);
  border-left: 0.2rem solid var(--md-primary-fg-color);
  border-radius: 0.1rem;
  box-shadow: var(--md-shadow-z1);
  padding: 0.9rem 1.1rem;
}

.type-card h3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  margin: 0 0 0.4rem;
}

.type-badge {
  background: var(--md-default-fg-color--lightest);
  border-radius: 0.1rem;
  color: var(--md-default-fg-color--light);
  font-family: "Roboto Mono", monospace;
  font-size: 0.7rem;
  padding: 0.1rem 0.35rem;
}

.type-desc { font-size: 0.85rem; color: var(--md-default-fg-color--light); margin: 0; }
.type-example { font-size: 0.8rem; color: var(--md-default-fg-color--lighter); margin: 0.4rem 0 0; }

/* ── Hero (home page) ───────────────────────────────────────── */
.hero {
  text-align: center;
  padding: 2rem 0 1rem;
}

.hero h1 {
  font-size: 2.4em;
  margin-bottom: 0.4em;
  color: var(--md-default-fg-color);
}

.hero__lede {
  font-size: 1.1em;
  color: var(--md-default-fg-color--light);
  max-width: 40rem;
  margin: 0 auto 1.5rem;
}

/* ── Notices ────────────────────────────────────────────────── */
.notice {
  border: 0.05rem solid var(--md-secondary-fg-color);
  border-left-width: 0.2rem;
  border-radius: 0.1rem;
  box-shadow: var(--md-shadow-z1);
  font-size: 0.85rem;
  padding: 0.6rem 0.9rem;
  margin: 1rem 0;
}

.notice--grid { grid-column: 1 / -1; }

/* ── Graph pages ────────────────────────────────────────────── */
#graphContainer {
  width: 100%;
  height: 80vh;
  background: var(--graph-bg);
  border: 0.05rem solid var(--md-default-fg-color--lightest);
  border-radius: 0.1rem;
}

.graph-panel {
  width: 100%;
  height: 500px;
  background: var(--graph-bg);
  border: 0.05rem solid var(--md-default-fg-color--lightest);
  border-radius: 0.1rem;
  overflow: hidden;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  background: var(--md-default-bg-color);
  border: 0.05rem solid var(--md-default-fg-color--lightest);
  border-radius: 0.1rem;
  box-shadow: var(--md-shadow-z1);
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
}

.controls__row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  align-items: center;
  width: 100%;
  font-size: 0.8rem;
  color: var(--md-default-fg-color--light);
}

.controls__row label { display: inline-flex; align-items: center; gap: 0.3rem; }

.controls.minimized { padding: 0.4rem 0.6rem; }

.controls.minimized .controls__row,
.controls.minimized > input,
.controls.minimized > button:not(#toggleControlsBtn) { display: none; }

/* The page shrinks its own heading when the controls are minimised, to give
   the graph the vertical space. */
.page.minimized .page__title { font-size: 1.25em; margin-bottom: 0.2em; }
.page.minimized .page__lede { display: none; }

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.9rem;
  align-items: center;
  font-size: 0.75rem;
  color: var(--md-default-fg-color--light);
}

.graph-legend__item { display: inline-flex; align-items: center; gap: 0.3rem; }

.graph-legend__swatch {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
}

/* One definition per node type, shared with the D3 code, which reads the same
   custom properties. The legend cannot disagree with the graph. */
.graph-legend__swatch--article  { background: var(--graph-article); }
.graph-legend__swatch--concept  { background: var(--graph-concept); }
.graph-legend__swatch--section  { background: var(--graph-section); }
.graph-legend__swatch--tag      { background: var(--graph-tag); }
.graph-legend__swatch--external { background: var(--graph-external); }
.graph-legend__swatch--entity   { background: var(--graph-entity); }

/* Graph labels: SVG text, so the colour has to be set rather than inherited. */
.graph-label {
  fill: var(--md-default-fg-color--light);
  pointer-events: none;
}

.context-menu {
  position: fixed;
  display: none;
  z-index: 2000;
  background: var(--md-default-bg-color);
  border: 0.05rem solid var(--md-default-fg-color--lightest);
  border-radius: 0.1rem;
  box-shadow: var(--md-shadow-z3);
  min-width: 15rem;
  max-width: 22rem;
  padding: 0.3rem 0;
  font-size: 0.8rem;
}

.context-menu-title {
  font-weight: 500;
  padding: 0.5rem 0.8rem 0.3rem;
  color: var(--md-default-fg-color);
}

.context-menu-info {
  font-size: 0.75rem;
  color: var(--md-default-fg-color--light);
  padding: 0 0.8rem 0.3rem;
}

.context-menu-url {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  font-family: "Roboto Mono", monospace;
  font-size: 0.7rem;
  color: var(--md-default-fg-color--lighter);
  border-top: 0.05rem solid var(--md-default-fg-color--lightest);
  margin-top: 0.3rem;
  padding: 0.4rem 0.8rem;
  word-break: break-all;
}

.context-menu-url__text { flex: 1; min-width: 0; }

.context-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--md-typeset-a-color);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
}

.context-menu-item:hover {
  background: var(--md-accent-fg-color--transparent);
  color: var(--md-accent-fg-color);
}

.copy-btn {
  background: transparent;
  border: 0.05rem solid var(--md-default-fg-color--lightest);
  border-radius: 0.1rem;
  color: var(--md-default-fg-color--light);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
}

.copy-btn:hover { border-color: var(--md-accent-fg-color); color: var(--md-accent-fg-color); }
.copy-btn.copied { background: var(--md-accent-fg-color); border-color: var(--md-accent-fg-color); color: #fff; }

.entity-highlight {
  background: var(--md-typeset-mark-color);
  border-radius: 0.1rem;
  padding: 0 0.1em;
}

:fullscreen {
  background: var(--md-default-bg-color);
  overflow: auto;
  padding: 1rem;
}

:fullscreen #graphContainer { height: calc(100vh - 11rem); }
:fullscreen .page__title { font-size: 1.5em; }
:fullscreen .page__lede { display: none; }
:fullscreen .context-menu { z-index: 99999; }

::backdrop { background: var(--md-default-bg-color); }

/* ══ Footer ════════════════════════════════════════════════════ */
.md-footer {
  background: var(--md-footer-bg-color);
  color: var(--md-footer-fg-color);
  font-size: 0.8rem;
  margin-top: 3rem;
}

.md-footer__inner {
  max-width: var(--md-grid-width);
  margin: 0 auto;
  padding: 1.2rem 0.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.5rem;
  align-items: center;
  justify-content: space-between;
}

.md-footer a { color: var(--md-footer-fg-color); }
.md-footer a:hover { color: var(--md-accent-fg-color); }

.md-footer__meta { color: var(--md-footer-fg-color--light); }

.md-footer__links { display: flex; flex-wrap: wrap; gap: 1rem; }

/* ══ Desktop layout ════════════════════════════════════════════ */
@media (min-width: 1024px) {
  /* The tracks themselves are defined once, further down, together with
     the rules that collapse them. No column gap: the rails carry their
     own gutter, as Material's do, so a collapsed rail gives all of its
     width back to the prose instead of leaving a gap behind. */
  .layout-container {
    display: grid;
    gap: 0;
    align-items: start;
  }

  /* The gutter is inside the column, so max-width has to allow for it:
     with border-box, the measure is max-width minus both gutters. */
  .main-content {
    padding: 1.2rem var(--md-prose-gutter) 3rem;
    max-width: calc(var(--md-content-width) + 2 * var(--md-prose-gutter));
    margin: 0;
  }

  .toc-sidebar,
  .refs-sidebar {
    position: sticky;
    top: 3rem;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
    border-top: 0;
    padding: 1.2rem 0;
    scrollbar-width: thin;
    scrollbar-color: var(--md-default-fg-color--lighter) transparent;
  }

  /* The gutter between a rail and the prose. Lives on the rail rather
     than in a grid gap so that collapsing the rail reclaims it. */
  .toc-sidebar { padding-right: var(--md-rail-gutter); }
  .refs-sidebar { padding-left: var(--md-rail-gutter); }

  .toc-sidebar::-webkit-scrollbar,
  .refs-sidebar::-webkit-scrollbar { width: 0.25rem; }

  .toc-sidebar::-webkit-scrollbar-thumb,
  .refs-sidebar::-webkit-scrollbar-thumb {
    background: var(--md-default-fg-color--lighter);
    border-radius: 0.1rem;
  }

  /* Collapsed rails park against the viewport edge. */
  .toc-sidebar.hidden,
  .refs-sidebar.hidden {
    position: fixed;
    top: 3rem;
    width: 2.4rem;
    padding: 0;
    z-index: 50;
    background: var(--md-default-bg-color);
    box-shadow: var(--md-shadow-z2);
    border-radius: 0 0.1rem 0.1rem 0;
    max-height: none;
    overflow: visible;
  }

  .toc-sidebar.hidden { left: 0; }
  .refs-sidebar.hidden { right: 0; border-radius: 0.1rem 0 0 0.1rem; }

  .toc-sidebar.hidden .toggle-btn,
  .refs-sidebar.hidden .toggle-btn {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    width: 2.4rem;
    padding: 0.8rem 0.4rem;
    border: 0;
  }

  /* ── Three columns, never four ──────────────────────────────
     Left rail, prose, and one right rail. Articles and concepts offer
     two right-hand panels — links and graph — but only one is ever open
     at a time, enforced in the page script, so they share a single
     track. Opening both left too little room for the prose and the
     panels ended up over the text.

     Each rail is keyed by id, not by class: the graph rail is also a
     .refs-sidebar, so a rule written against .refs-sidebar.hidden
     matches both and collapses the wrong column.

     Every item states its column. A collapsed rail becomes fixed and
     leaves the grid flow, and without explicit placement the prose
     would be auto-placed into whichever track came free, including a
     zero-width one. */
  /* The prose gets a guaranteed width; the rails are the flexible tracks
     and absorb everything left over, which is what carries them out
     towards the screen edges as the viewport grows.
     
     The order matters. Grid's maximise step hands free space to tracks
     equally, so a flexible prose track with a zero base loses out to the
     rails and ends up narrower than either of them. Making the rails the
     fr tracks means they are served last, after the prose has reached its
     cap. */
  .layout-container {
    --col-toc: minmax(var(--md-nav-width), 1fr);
    --col-aside: minmax(var(--md-aside-width), 1fr);
    grid-template-columns:
      var(--col-toc)
      minmax(0, calc(var(--md-content-width) + 2 * var(--md-prose-gutter)))
      var(--col-aside);
    justify-content: center;
    /* Room for the parked rails, which sit against the right edge.
       There is always at least one of them, so the gutter is always
       reserved and a parked toggle can never cover the open panel. */
    padding-right: 2.4rem;
  }

  #tocSidebar { grid-column: 1; }
  .main-content { grid-column: 2; }
  #refsSidebar,
  #graphSidebar { grid-column: 3; }

  /* A rail's track may run wider than its content needs on a large
     display. The panel keeps to a readable width and sits against the
     prose, so the gutter between them never changes; the slack collects
     on the outer side. */
  .toc-sidebar > *,
  .refs-sidebar > * {
    max-width: var(--md-rail-content-max);
  }

  .toc-sidebar > * { margin-left: auto; }
  .refs-sidebar > * { margin-right: auto; }

  /* A collapsed rail drops its floor to the width of its parked toggle but
     stays flexible. Making it fixed instead would hand all of its space to
     the opposite rail, which pushes the prose off centre; sharing it keeps
     the prose in the middle whichever panels are open. */
  .layout-container:has(#tocSidebar.hidden) {
    --col-toc: minmax(2.4rem, 1fr);
    padding-left: 0;
  }

  .layout-container:has(#refsSidebar.hidden):has(#graphSidebar.hidden),
  .layout-container:has(#refsSidebar.hidden):not(:has(#graphSidebar)) {
    --col-aside: minmax(2.4rem, 1fr);
  }

  /* Centred in its track, so collapsing a rail widens the measure
     rather than leaving the text against one edge. */
  .main-content { margin-inline: auto; }

  /* Parked rails stack at different heights so every toggle stays
     reachable when both panels are closed. */
  #refsSidebar.hidden { top: 3rem; }
  #graphSidebar.hidden { top: 9rem; }
}

/* Between 1024 and 1200 there is not enough room for both an 18rem rail
   and a readable measure, so the rails give up their floor first. */
@media (min-width: 1024px) and (max-width: 1200px) {
  .layout-container {
    --md-nav-width: 15rem;
    --md-aside-width: 15rem;
  }
}

/* ══ Mobile ════════════════════════════════════════════════════ */
@media (max-width: 1023px) {
  .toc-sidebar,
  .refs-sidebar { padding: 1rem 0; }
  /* Single column here, so the shell's own padding is the only gutter
     the prose needs; keeping both would waste a fifth of a phone screen. */
  .main-content { max-width: none; --md-prose-gutter: 0rem; }
}

@media (max-width: 768px) {
  .page { padding: 1rem 0.8rem 2rem; }
  .nav-content { height: 2.8rem; padding: 0 0.6rem; }
  .home-link { font-size: 1rem; }
  .nav-toggle { display: flex; margin-left: auto; }
  .nav-menu + .nav-toggle { margin-left: 0; }

  .nav-menu {
    position: absolute;
    top: 2.8rem;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--md-primary-fg-color);
    box-shadow: var(--md-shadow-z2);
    padding: 0.3rem 0;
    display: none;
    margin-left: 0;
  }

  .nav-menu.open { display: flex; }

  .nav-link { border-radius: 0; padding: 0.7rem 1rem; text-align: left; }

  .nav-divider { width: 100%; height: 1px; margin: 0.3rem 0; }

  h1 { font-size: 1.75em; }
  h2 { font-size: 1.375em; }
  h3 { font-size: 1.125em; }

  .hero { padding: 1rem 0; }
  .hero h1 { font-size: 1.85em; }

  .grid { grid-template-columns: 1fr; }
  #graphContainer { height: 60vh; }
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Print: drop the chrome, keep the prose. */
@media print {
  .md-header,
  .md-footer,
  .toc-sidebar,
  .refs-sidebar,
  .controls { display: none; }

  .layout-container { display: block; }
  .main-content { max-width: none; }
}
