/* ==========================================================================
   epistemic-ontology.net
   One stylesheet, no build step, no webfonts, no runtime dependencies.

   Theming: tokens are declared once for light. The dark overrides appear
   TWICE — once under `prefers-color-scheme` (for data-theme="auto") and once
   under an explicit data-theme="dark". Keep those two blocks in sync; they are
   deliberately adjacent so a change to one makes the other obvious.
   ========================================================================== */

/* --- Tokens -------------------------------------------------------------- */

:root {
  --is-dark: 0;

  --bg: #fbfcfd;
  --bg-alt: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --ink: #16202e;
  --ink-soft: #33415a;
  --muted: #5d6b80;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --accent: #24508f;
  --accent-ink: #1b3f74;
  --accent-soft: #e9f0fb;
  --shadow: 0 1px 2px rgba(15, 30, 60, .05), 0 8px 24px -12px rgba(15, 30, 60, .14);
  --shadow-lift: 0 2px 4px rgba(15, 30, 60, .06), 0 16px 32px -16px rgba(15, 30, 60, .22);

  --code-bg: #f5f7fb;
  --t-comment: #6b7a90;
  --t-string: #146b52;
  --t-keyword: #8250a8;
  --t-iri: #24508f;
  --t-prefix: #a8551f;
  --t-number: #1f6f8b;

  --measure: 68ch;
  --wrap: 74rem;
  --radius: 14px;
  --radius-sm: 8px;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --is-dark: 1;
    --bg: #0d1117;
    --bg-alt: #121924;
    --surface: #151c27;
    --surface-2: #1a2331;
    --ink: #e7edf6;
    --ink-soft: #c4d0e0;
    --muted: #94a2b8;
    --line: #253141;
    --line-strong: #35455a;
    --accent: #83b3ff;
    --accent-ink: #a9caff;
    --accent-soft: #17263d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, .45), 0 16px 32px -16px rgba(0, 0, 0, .7);
    --code-bg: #111823;
    --t-comment: #7d8ca3;
    --t-string: #7ec9a9;
    --t-keyword: #c79bec;
    --t-iri: #86b6ff;
    --t-prefix: #e0a06a;
    --t-number: #6fc7d8;
  }
}

:root[data-theme="dark"] {
  --is-dark: 1;
  --bg: #0d1117;
  --bg-alt: #121924;
  --surface: #151c27;
  --surface-2: #1a2331;
  --ink: #e7edf6;
  --ink-soft: #c4d0e0;
  --muted: #94a2b8;
  --line: #253141;
  --line-strong: #35455a;
  --accent: #83b3ff;
  --accent-ink: #a9caff;
  --accent-soft: #17263d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, .45), 0 16px 32px -16px rgba(0, 0, 0, .7);
  --code-bg: #111823;
  --t-comment: #7d8ca3;
  --t-string: #7ec9a9;
  --t-keyword: #c79bec;
  --t-iri: #86b6ff;
  --t-prefix: #e0a06a;
  --t-number: #6fc7d8;
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

/* --- Base ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
}

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { line-height: 1.2; letter-spacing: -0.021em; color: var(--ink); }
h1 { font-size: clamp(2rem, 1.4rem + 2.4vw, 2.9rem); margin: 0 0 .6rem; }
h2 { font-size: clamp(1.35rem, 1.2rem + .7vw, 1.65rem); }
h3 { font-size: 1.15rem; }

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

img { max-width: 100%; height: auto; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }

code, .mono, pre { font-family: var(--mono); font-size: .875em; }
.wrap-anywhere { overflow-wrap: anywhere; }
.dim { color: var(--muted); }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 1.5rem; }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff; padding: .7rem 1.1rem;
  border-radius: 0 0 var(--radius-sm) 0; font-weight: 600;
}
.skip:focus { left: 0; }

/* --- Header -------------------------------------------------------------- */

.site-header {
  position: sticky; top: 0; z-index: 40;
  border-bottom: 1px solid var(--line);
  background: var(--bg);                                  /* fallback first */
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
}
@supports not (backdrop-filter: blur(1px)) { .site-header { background: var(--bg); } }

.header-inner {
  display: flex; align-items: center; gap: 1rem;
  min-height: 4rem; flex-wrap: wrap;
}
.brand {
  display: inline-flex; align-items: center; gap: .6rem;
  font-weight: 700; font-size: 1.08rem; letter-spacing: -.02em;
  color: var(--ink); text-decoration: none; margin-right: auto;
}
.brand:hover { color: var(--ink); }
.brand-mark { width: 32px; height: 32px; border-radius: 7px; flex: none; }
.brand-accent { color: var(--accent); }

.nav { display: flex; gap: .35rem; flex-wrap: wrap; }
.nav a {
  color: var(--muted); text-decoration: none; font-size: .95rem; font-weight: 500;
  padding: .4rem .65rem; border-radius: var(--radius-sm);
}
.nav a:hover { color: var(--ink); background: var(--bg-alt); }
.nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; flex: none;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--muted); cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--line-strong); }
.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .icon-sun { display: none; }
  :root[data-theme="auto"] .icon-moon { display: block; }
}

/* --- Hero ---------------------------------------------------------------- */

.hero {
  padding: clamp(2.5rem, 1rem + 6vw, 5rem) 0 clamp(2rem, 1rem + 3vw, 3.5rem);
  background:
    radial-gradient(60rem 30rem at 15% -10%, var(--accent-soft), transparent 65%),
    var(--bg);
  border-bottom: 1px solid var(--line);
}
.hero-inner {
  display: grid; gap: clamp(1.5rem, 4vw, 3.5rem);
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
}
@media (min-width: 56rem) {
  .hero-inner { grid-template-columns: 18rem minmax(0, 1fr); }
}
.hero-logo { width: min(300px, 60%); height: auto; justify-self: start; }
@media (min-width: 56rem) { .hero-logo { width: 100%; } }

.eyebrow {
  margin: 0 0 .75rem; font-size: .78rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase; color: var(--accent);
}
.lead { font-size: 1.15rem; color: var(--ink-soft); max-width: 46rem; margin: 0 0 1.25rem; }
.hero-ns { color: var(--muted); font-size: .85rem; margin: 1.5rem 0 0; }

.cta-row { display: flex; gap: .75rem; flex-wrap: wrap; margin: 1.5rem 0 0; }
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .6rem 1.15rem; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); font-weight: 600; font-size: .95rem; text-decoration: none;
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn:hover { color: var(--ink); box-shadow: var(--shadow); transform: translateY(-1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { color: #fff; }
:root[data-theme="dark"] .btn-primary { color: #0d1117; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .btn-primary,
  :root[data-theme="auto"] .btn-primary:hover { color: #0d1117; }
}

/* --- Bands & sections ---------------------------------------------------- */

.band { padding: clamp(2.5rem, 1rem + 4vw, 4rem) 0; }
.band-alt { background: var(--bg-alt); border-block: 1px solid var(--line); }
.section-title { margin: 0 0 .5rem; }
.section-note { color: var(--muted); max-width: var(--measure); margin: 0 0 2rem; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.more { font-weight: 600; font-size: .95rem; text-decoration: none; }

/* --- Cards --------------------------------------------------------------- */

.cards {
  display: grid; gap: 1.25rem;
  grid-template-columns: repeat(auto-fit, minmax(min(21rem, 100%), 1fr));
}
.card {
  display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 1.4rem 1.5rem;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); border-color: var(--line-strong); }
.card-companion { background: var(--surface-2); }
.card-head { display: flex; align-items: start; justify-content: space-between; gap: .75rem; }
.card h3 { margin: 0 0 .35rem; font-size: 1.2rem; }
.card h3 a { color: var(--ink); text-decoration: none; }
.card h3 a:hover { color: var(--accent); }
.card .ns { color: var(--muted); font-size: .78rem; margin: 0 0 .9rem; overflow-wrap: anywhere; }
.card-body { margin: 0 0 1.25rem; color: var(--ink-soft); font-size: .97rem; }

.card-stats { display: flex; gap: 1.5rem; margin: 0 0 1.25rem; flex-wrap: wrap; }
.card-stats > div { display: flex; flex-direction: column; }
.card-stats dt { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.card-stats dd { margin: 0; font-weight: 600; font-size: .95rem; }

.meta { margin-top: auto; display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }

.badge {
  display: inline-block; font-size: .72rem; font-weight: 600; letter-spacing: .02em;
  padding: .2rem .6rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink);
  border: 1px solid transparent;
}
:root[data-theme="dark"] .badge { color: var(--accent); }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .badge { color: var(--accent); } }
.badge-version {
  background: var(--surface-2); color: var(--muted);
  border-color: var(--line); font-family: var(--mono); white-space: nowrap;
}

/* --- Diagram ------------------------------------------------------------- */

.diagram { margin: 0; overflow-x: auto; }
.diagram svg { width: 100%; min-width: 42rem; height: auto; display: block; }
.d-box { fill: var(--surface); stroke: var(--line-strong); stroke-width: 1.2; }
.d-core { fill: var(--accent-soft); stroke: var(--accent); }
.d-label { fill: var(--ink); font: 600 14px var(--font); }
.d-sub { fill: var(--muted); font: 400 11.5px var(--mono); }
.d-edge { stroke: var(--line-strong); stroke-width: 1.6; }
.d-dashed { stroke-dasharray: 5 4; }
.d-arrow { fill: var(--line-strong); }
.d-edge-label { fill: var(--muted); font: 500 11px var(--font); }
.d-caption { fill: var(--muted); font: italic 12.5px var(--font); }

/* --- Document layout ----------------------------------------------------- */

.doc-head { padding: clamp(2rem, 1rem + 3vw, 3.25rem) 1.5rem 1.5rem; }
.doc-head .lead { margin-bottom: 1rem; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 1rem; }
.crumbs a { text-decoration: none; }
.crumbs span[aria-hidden] { margin: 0 .35rem; opacity: .5; }
.meta-line { color: var(--muted); font-size: .9rem; margin: .75rem 0 0; }
.version-note {
  margin: 1.25rem 0 0; padding: .8rem 1rem; font-size: .92rem;
  border-left: 3px solid var(--accent); background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--ink-soft);
}

.doc-layout { display: grid; gap: 2.5rem; align-items: start; padding-bottom: 3rem; }
@media (min-width: 62rem) {
  .doc-layout { grid-template-columns: 16rem minmax(0, 1fr); gap: 3rem; }
  /* build.py adds this when there is nothing to put in the sidebar */
  .doc-layout.no-sidebar { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: sticky; top: 5rem; max-height: calc(100vh - 6.5rem); overflow-y: auto; }
}

.sidebar-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 1.1rem 1.25rem; margin-bottom: 1.25rem;
}
.sidebar-title {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 0 0 .8rem;
}
.facts { margin: 0; display: grid; grid-template-columns: 1fr; gap: .1rem; font-size: .88rem; }
.facts dt { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; margin-top: .7rem; }
.facts dt:first-child { margin-top: 0; }
.facts dd { margin: .1rem 0 0; }
.facts dd a { overflow-wrap: anywhere; }

.toc ol { list-style: none; margin: 0; padding: 0; font-size: .88rem; }
.toc li { margin: .1rem 0; }
.toc a { display: block; padding: .3rem .5rem; border-radius: 6px; color: var(--muted); text-decoration: none; border-left: 2px solid transparent; }
.toc a:hover { color: var(--accent); background: var(--bg-alt); }
.toc .toc-l3 a { padding-left: 1.25rem; font-size: .85em; }
ul.plain { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
ul.plain li { margin: .35rem 0; }

/* --- Prose --------------------------------------------------------------- */

.prose { max-width: var(--measure); }
.doc-body { min-width: 0; }
.prose > section, .prose > h2 { margin-top: 2.75rem; }
.prose > section:first-child, .prose > h2:first-child { margin-top: 0; }
.prose > section > h2:first-child { margin-top: 0; }
.prose h2 { padding-bottom: .4rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.prose h3 { margin: 2rem 0 .6rem; }
.prose h4 { margin: 1.5rem 0 .4rem; font-size: 1rem; color: var(--ink-soft); }
.prose p, .prose ul, .prose ol { margin: 0 0 1.1rem; }
.prose li { margin: .35rem 0; }
.prose li > ul, .prose li > ol { margin: .35rem 0; }
.prose strong { color: var(--ink); font-weight: 650; }
.prose em { color: inherit; }

.prose blockquote {
  margin: 1.5rem 0; padding: .9rem 1.25rem;
  border-left: 3px solid var(--accent);
  background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--ink-soft);
}
.prose blockquote > :last-child { margin-bottom: 0; }

.prose h2 a, .prose h3 a { text-decoration: none; }

/* --- Code ---------------------------------------------------------------- */

pre {
  background: var(--code-bg); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 1rem 1.15rem;
  overflow-x: auto; line-height: 1.55; margin: 0 0 1.25rem;
  tab-size: 2;
}
pre code { font-size: .84rem; background: none; padding: 0; border: 0; }
:not(pre) > code {
  background: var(--code-bg); padding: .12rem .38rem; border-radius: 5px;
  border: 1px solid var(--line); color: var(--ink-soft); white-space: nowrap;
}

.t-c { color: var(--t-comment); font-style: italic; }
.t-s { color: var(--t-string); }
.t-k { color: var(--t-keyword); font-weight: 600; }
.t-i { color: var(--t-iri); }
.t-p { color: var(--t-prefix); }
.t-n { color: var(--t-number); }
.t-l { color: var(--t-comment); }

/* --- Tables -------------------------------------------------------------- */

.table-scroll { overflow-x: auto; margin: 0 0 1.25rem; }
table { border-collapse: collapse; width: 100%; font-size: .93rem; margin: 0 0 1.25rem; }
.table-scroll table { margin: 0; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th {
  color: var(--muted); font-weight: 600; font-size: .76rem;
  text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--line-strong);
}
tbody tr:hover { background: var(--surface-2); }
td code { white-space: nowrap; }
.files td:first-child { white-space: nowrap; }

/* --- Post lists ---------------------------------------------------------- */

.post-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.25rem; }
.post-list-full { gap: 0; }
.post-item {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 1.3rem 1.5rem;
}
.post-list-full .post-item {
  border: 0; border-bottom: 1px solid var(--line); border-radius: 0;
  background: none; padding: 1.6rem 0;
}
.post-item time { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.post-item h2, .post-item h3 { margin: .3rem 0 .5rem; font-size: 1.2rem; }
.post-list-full .post-item h2 { font-size: 1.35rem; }
.post-item h2 a, .post-item h3 a { color: var(--ink); text-decoration: none; }
.post-item h2 a:hover, .post-item h3 a:hover { color: var(--accent); }
.post-item p { margin: 0; color: var(--ink-soft); font-size: .97rem; }
.post-tags { margin-top: .7rem !important; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

.tag-bar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; padding: 1.25rem 0; border-bottom: 1px solid var(--line); }
.tag-bar-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-right: .25rem; }
.tag {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .25rem .7rem; border-radius: 999px; font-size: .8rem; font-weight: 500;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--ink-soft); text-decoration: none;
}
.tag:hover { border-color: var(--accent); color: var(--accent); }
.tag-sm { font-size: .75rem; padding: .1rem .55rem; }
.tag-count { color: var(--muted); font-size: .75em; font-variant-numeric: tabular-nums; }

.post-nav {
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  border-top: 1px solid var(--line); padding: 1.75rem 0 3rem;
}
.post-nav-link {
  display: flex; flex-direction: column; gap: .2rem; max-width: 22rem;
  text-decoration: none; font-weight: 600; font-size: .97rem;
}
.post-nav-link .dim { font-weight: 500; font-size: .8rem; }
.post-nav-next { text-align: right; }

.back { display: inline-block; margin: 1.5rem 0 3rem; font-size: .92rem; text-decoration: none; }

/* --- Footer -------------------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--line); background: var(--surface);
  padding: 2.5rem 0; margin-top: auto; color: var(--muted); font-size: .9rem;
}
.footer-inner { display: flex; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; align-items: start; }
.footer-brand { margin: 0; font-weight: 700; color: var(--ink); }
.footer-note { margin: .2rem 0 0; }
.footer-nav { display: flex; gap: 1.25rem; flex-wrap: wrap; }
.footer-nav a { text-decoration: none; }
.footer-copy { margin: 0; }

/* --- Print --------------------------------------------------------------- */

@media print {
  .site-header, .site-footer, .sidebar, .theme-toggle, .cta-row, .post-nav, .skip { display: none; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .doc-layout { display: block; }
  .prose { max-width: none; }
  a { color: #000; text-decoration: underline; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: .85em; color: #444; }
  pre { border: 1px solid #ccc; background: #fafafa; }
}
