:root {
  color-scheme: light dark;
  --bg: #fffdfa;
  --fg: #11110f;
  --muted: #5f5a52;
  --faint: #8b8478;
  --line: #d8d0c3;
  --surface: #f6efe5;
  --code: #f1e6d7;
  --accent: #742d00;
  --focus: #005fcc;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #070707;
    --fg: #f1efe7;
    --muted: #b9b1a4;
    --faint: #8e867a;
    --line: #34302a;
    --surface: #14120f;
    --code: #1d1a15;
    --accent: #ffb86b;
    --focus: #8ab4ff;
  }
}

* { box-sizing: border-box; }

html {
  font-size: clamp(17px, 1.15vw, 20px);
  -webkit-text-size-adjust: 100%;
}

body {
  max-width: 88ch;
  margin: 0 auto;
  padding: 1.15rem clamp(0.95rem, 4vw, 2rem) 5rem;
  background: var(--bg);
  color: var(--fg);
  font: 1rem/1.64 ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--fg);
  color: var(--bg);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip {
  position: absolute;
  left: 1rem;
  top: 0.5rem;
  transform: translateY(-200%);
  background: var(--fg);
  color: var(--bg);
  padding: 0.35rem 0.55rem;
  z-index: 10;
}

.skip:focus { transform: translateY(0); }

.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.8rem 1.2rem;
  flex-wrap: wrap;
  padding: 0 0 0.85rem;
  margin: 0 0 clamp(2rem, 6vw, 4rem);
  border-bottom: 1px solid var(--line);
}

.site-id,
.site-nav,
.kicker,
.meta,
.crumb,
.action-row,
.fingerprint,
pre,
code,
kbd,
samp {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.site-id {
  margin: 0;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.site-id a {
  color: var(--fg);
  font-weight: 700;
  text-decoration: none;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  font-size: 0.82rem;
}

.site-nav a {
  color: var(--fg);
  text-decoration: none;
  padding: 0.18rem 0.4rem;
  border: 1px solid transparent;
}

.site-nav a:hover,
.site-nav a:focus-visible,
.site-nav a[aria-current="page"] {
  border-color: var(--fg);
  background: var(--surface);
  box-shadow: 2px 2px 0 var(--fg);
}

main:focus { outline: none; }

a {
  color: inherit;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

a:hover { color: var(--accent); }

a[href^="http"]:not(.no-mark)::after {
  content: "↗";
  font-size: 0.72em;
  padding-left: 0.12em;
}

h1,
h2,
h3 {
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.05;
  letter-spacing: -0.035em;
  margin: 0 0 0.55em;
}

h1 {
  font-size: clamp(2.25rem, 9vw, 5.2rem);
  letter-spacing: -0.075em;
}

.page-title h1,
.post-header h1 {
  max-width: 14ch;
}

.hero h1 {
  max-width: 10.5ch;
  line-height: 0.92;
}

h2 {
  font-size: clamp(1.35rem, 4.5vw, 2.1rem);
  margin-top: 2.2rem;
}

h3 { font-size: 1.1rem; }

p,
ul,
ol,
blockquote,
pre,
.archive-list {
  margin-top: 0;
  margin-bottom: 1rem;
}

.lede,
.dek {
  font-size: clamp(1.1rem, 1.8vw, 1.34rem);
  line-height: 1.48;
  color: var(--fg);
}

.kicker,
.meta,
.crumb {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
  letter-spacing: 0.045em;
  text-transform: uppercase;
}

.meta {
  text-transform: none;
  letter-spacing: 0;
}

.muted { color: var(--muted); }

.rule {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 2.5rem 0;
}

.diagram,
.key-block {
  overflow-x: auto;
  white-space: pre;
  border: 1px solid var(--line);
  border-left: 0.45rem solid var(--fg);
  background: var(--surface);
  padding: 0.85rem 1rem;
  font-size: 0.84rem;
  line-height: 1.5;
}

.key-block {
  border-left-color: var(--accent);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.equation {
  overflow-x: auto;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-left: 0.45rem solid var(--accent);
  background: var(--surface);
  padding: 0.85rem 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.84rem;
  line-height: 1.5;
}

code,
kbd,
samp {
  background: var(--code);
  padding: 0.04rem 0.22rem;
  border-radius: 0.18rem;
  font-size: 0.92em;
}

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

.index-list,
.ledger,
.post-list,
.archive-list {
  padding-left: 0;
}

.index-list {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--line);
}

.index-list article {
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
}

.index-list h3,
.post-list h2,
.post-list h3,
.ledger h3 {
  margin-bottom: 0.25rem;
}

.compact {
  padding-left: 1.15rem;
}

.compact li + li { margin-top: 0.35rem; }

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(12rem, 0.52fr);
  gap: 2rem;
  align-items: start;
}

.aside-box,
.thesis,
.note {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface), transparent);
  padding: 1rem;
}

.aside-box h2:first-child { margin-top: 0; }

.thesis {
  border-left: 0.45rem solid var(--accent);
}

.thesis p,
.section-index p {
  margin-bottom: 0.45rem;
}

.thesis-title,
.section-index > p {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.4;
  letter-spacing: 0.045em;
  text-transform: uppercase;
}

.section-index {
  margin: 1.75rem 0 2.25rem;
  padding: 1rem;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface), transparent);
}

.section-index ol {
  margin: 0;
  padding-left: 1.15rem;
  columns: 2 14rem;
  column-gap: 1.6rem;
  font-size: 0.9rem;
}

.section-index li {
  break-inside: avoid;
  margin: 0.18rem 0;
}

.citation {
  color: var(--accent);
  font-size: 0.72em;
  padding-left: 0.08em;
  text-decoration: none;
  vertical-align: super;
}

.citation:hover,
.citation:focus-visible {
  text-decoration: underline;
}

.post-list,
.ledger {
  list-style: none;
  counter-reset: item;
  border-top: 1px solid var(--line);
}

.post-list > li,
.ledger > li {
  counter-increment: item;
  display: grid;
  grid-template-columns: 3.5ch minmax(0, 1fr);
  gap: 1rem;
  padding: 1.15rem 0;
  border-bottom: 1px solid var(--line);
}

.post-list > li::before,
.ledger > li::before {
  content: counter(item, decimal-leading-zero);
  color: var(--faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  padding-top: 0.15rem;
}

.post-list.long > li {
  grid-template-columns: 4ch minmax(0, 1fr);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: baseline;
  font-size: 0.82rem;
}

.action-row a {
  display: inline-block;
  padding: 0.12rem 0.4rem;
  border: 1px solid var(--line);
  background: var(--surface);
  text-decoration: none;
}

.action-row a:hover,
.action-row a:focus-visible {
  border-color: var(--fg);
  box-shadow: 2px 2px 0 var(--fg);
}

.social-links {
  margin: 1.1rem 0 1.4rem;
}

.archive-list {
  columns: 2 14rem;
  list-style: none;
  border-top: 1px solid var(--line);
}

.archive-list li {
  break-inside: avoid;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
}

.prose {
  max-width: 74ch;
}

.post-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.prose h2 {
  margin-top: 2rem;
}

blockquote {
  margin-left: 0;
  padding-left: 1rem;
  border-left: 0.35rem solid var(--line);
  color: var(--muted);
}

.references {
  padding-left: 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.references li {
  margin-bottom: 0.75rem;
}

.references a {
  color: var(--fg);
}

.backlink {
  margin-top: 2rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.85rem;
}

.fingerprint code {
  display: inline-block;
  padding: 0.45rem 0.55rem;
  font-size: clamp(0.75rem, 2vw, 0.95rem);
  overflow-wrap: anywhere;
}

.site-footer {
  margin-top: clamp(3rem, 8vw, 5rem);
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.86rem;
}

.site-footer p { margin-bottom: 0.4rem; }

@media (max-width: 720px) {
  .split { display: block; }
  .post-list > li,
  .ledger > li,
  .post-list.long > li {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }
  .post-list > li::before,
  .ledger > li::before { padding-top: 0; }
  .site-header { align-items: flex-start; }
}

@media print {
  :root {
    --bg: #fff;
    --fg: #000;
    --muted: #333;
    --line: #999;
    --surface: #fff;
    --code: #fff;
  }
  body {
    max-width: none;
    padding: 0.5in;
    font-size: 11pt;
  }
  .site-nav,
  .skip { display: none; }
  a[href^="http"]::after,
  a[href^="/" ]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }
  .diagram,
  .key-block,
  .equation,
  .aside-box,
  .thesis,
  .section-index {
    border-color: #000;
    background: #fff;
  }
}
