:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --text: #1a1a1a;
  --muted: #5a5a5a;
  --faint: #9a9a9a;
  --accent: #4a3aff;
  --accent-soft: #ecebfb;
  --border: #e2e2e2;
  --ink: #1f1d3d;
  --ok: #1e8449;
  --warn: #b9770e;
  --bad: #c0392b;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6; font-size: 17px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header.site-header {
  background: var(--ink); color: #fff;
  padding: 14px 24px; border-bottom: 1px solid #15132a;
}
header.site-header .nav-inner {
  max-width: 860px; margin: 0 auto;
  display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
}
header.site-header .brand { font-weight: 600; font-size: 1.1rem; color: #fff; }
header.site-header nav { display: flex; flex-wrap: wrap; gap: 0 18px; }
header.site-header nav a { color: #fff; opacity: 0.85; font-size: 0.95rem; }
header.site-header nav a:hover { opacity: 1; }
header.site-header nav a.current { opacity: 1; text-decoration: underline; text-underline-offset: 4px; }

main { max-width: 860px; margin: 32px auto; padding: 0 24px 60px; }
main.wide { max-width: 1100px; }
h1 { font-size: 2.1rem; margin: 0 0 4px; line-height: 1.2; }
.subtitle { color: var(--muted); font-size: 1.12rem; margin: 0 0 24px; }
h2 {
  font-size: 1.3rem; margin: 2.2em 0 0.6em;
  border-bottom: 1px solid var(--border); padding-bottom: 4px;
}
h3 { font-size: 1.05rem; margin: 1.6em 0 0.4em; color: var(--ink); }
p { margin: 0.8em 0; }
.lead { font-size: 1.07rem; }
ul { padding-left: 1.3em; }
li { margin-bottom: 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
code {
  background: #f3f3f7; padding: 1px 5px;
  border-radius: 3px; font-size: 0.92em;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
}
pre {
  background: #f3f3f7; padding: 12px 14px; border-radius: 6px; overflow-x: auto;
  font-size: 0.85em; font-family: "SFMono-Regular", Menlo, Consolas, monospace; line-height: 1.45;
}
pre code { background: none; padding: 0; font-size: inherit; }
blockquote {
  margin: 18px 0; padding: 10px 18px;
  border-left: 3px solid #ddd; color: var(--muted);
}
.equation-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px 18px; margin: 18px 0;
  text-align: center; overflow-x: auto;
}

/* diagrams */
.diagram { margin: 26px 0 10px; }
.diagram svg { width: 100%; height: auto; display: block; }
.diagram .caption {
  text-align: center; color: var(--muted);
  font-size: 0.9rem; margin: 6px 0 0;
}

/* tables */
.table-wrap { overflow-x: auto; margin: 18px 0; }
table.impl { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.impl th, table.impl td {
  text-align: left; padding: 11px 14px;
  border-bottom: 1px solid var(--border); vertical-align: top;
}
table.impl thead th {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 600; border-bottom: 2px solid var(--border);
}
table.impl tbody td:first-child { font-weight: 600; white-space: nowrap; }
table.impl tr:last-child td { border-bottom: none; }
table.impl .mode { color: var(--muted); font-size: 0.9rem; }
table.impl.compact { font-size: 0.88rem; }
table.impl.compact th, table.impl.compact td { padding: 7px 10px; }
table.impl.compact tbody td:first-child { white-space: normal; }
table.impl td.c { text-align: center; }

/* tags */
.tag {
  display: inline-block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.03em;
  text-transform: uppercase; padding: 1px 7px; border-radius: 10px;
  background: var(--accent-soft); color: var(--ink); white-space: nowrap; vertical-align: middle;
}
.tag.open { background: #e6f4ea; color: var(--ok); }
.tag.academic { background: #fdf2dc; color: var(--warn); }
.tag.commercial { background: #fbe9e7; color: var(--bad); }
.tag.mixed { background: #eeeeee; color: var(--muted); }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin: 18px 0; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px;
}
.card h3 { margin: 0 0 6px; font-size: 1rem; }
.card p { margin: 4px 0; font-size: 0.93rem; }
.card .meta { color: var(--muted); font-size: 0.85rem; }

/* bibliography */
.bib h3 { font-size: 1.02rem; margin-top: 1.4em; color: var(--ink); }
.bib ul { list-style: none; padding-left: 0; }
.bib li { margin-bottom: 12px; padding-left: 1.2em; text-indent: -1.2em; }

.pagenav { margin: 0 0 22px; font-size: 0.95rem; }
.next-steps {
  background: var(--accent-soft); border-radius: 8px;
  padding: 4px 20px; margin: 24px 0;
}
.toc { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px 18px; margin: 18px 0; font-size: 0.95rem; }
.toc ul { margin: 6px 0; }
.toc li { margin-bottom: 3px; }

/* essay */
.essay h2 { margin-top: 2em; }
.essay h3 { font-size: 1.05rem; margin-top: 1.5em; }
.essay ol.sources { font-size: 0.92rem; color: var(--muted); padding-left: 1.4em; }

/* d3 pages (timeline, map) */
#tl-wrap, #map-wrap { max-width: 1100px; margin: 0 auto; padding: 16px 24px; }
#timeline, #graph { width: 100%; border: 1px solid #ddd; background: #fdfdfc; border-radius: 4px; }
#timeline { height: 1075px; }
#graph { height: 1000px; }
.legend { font-size: 0.85em; color: #444; display: flex; flex-wrap: wrap; gap: 14px 22px; margin: 10px 0; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.line { width: 26px; height: 0; border-top: 2.5px solid #999; display: inline-block; }
#tooltip { position: absolute; pointer-events: none; background: rgba(34,34,34,0.95); color: #eee;
  padding: 8px 11px; border-radius: 4px; font-size: 13px; max-width: 360px; display: none; line-height: 1.35; z-index: 10; }
text.evlabel { font: 11px sans-serif; fill: #222; }
text.lanelabel { font: bold 12px sans-serif; fill: #555; }
text.yearlabel { font: 11px sans-serif; fill: #888; }
text.nodelabel { font: 11px sans-serif; fill: #222; pointer-events: none; }
text.edgelabel { font: italic 9.5px sans-serif; pointer-events: none;
  paint-order: stroke; stroke: #fdfdfc; stroke-width: 3.5px; stroke-linejoin: round; }
.hint { color:#666; font-size: 0.9em; }

footer {
  max-width: 860px; margin: 40px auto 24px; padding: 16px 24px;
  font-size: 0.85rem; color: var(--muted); border-top: 1px solid var(--border);
}
@media (max-width: 600px) {
  html, body { font-size: 16px; }
  h1 { font-size: 1.7rem; }
  #timeline { height: 560px; }
  #graph { height: 560px; }
}
