:root {
  --bg: #f0eee7;
  --paper: #fffefa;
  --ink: #161616;
  --muted: #63645e;
  --faint: #8b8d86;
  --line: #d8d5ca;
  --green: #2f7651;
  --amber: #a96f08;
  --blue: #245da8;
  --red: #a73d31;
  --wash: #edf3ed;
  --note: #f7f2e4;
  --reader: "Atkinson Hyperlegible", ui-sans-serif, system-ui, sans-serif;
  --display: "Atkinson Hyperlegible", ui-sans-serif, system-ui, sans-serif;
  --math: "STIX Two Text", Georgia, serif;
  --mono: "SF Mono", SFMono-Regular, Menlo, monospace;
  color-scheme: light;
  font-family: var(--reader);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--ink);
  margin: 0;
}

button {
  font: inherit;
}

a {
  color: inherit;
}

.topbar {
  align-items: center;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 21px;
  grid-template-columns: 236px 1fr auto;
  min-height: 61px;
  padding: 0 21px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  align-items: center;
  color: var(--ink);
  display: inline-flex;
  font-family: var(--display);
  font-size: 24px;
  gap: 13px;
  text-decoration: none;
}

.mark {
  background:
    radial-gradient(circle, var(--ink) 1.4px, transparent 2px) 0 0 / 8px 8px;
  border: 1px solid var(--line);
  border-radius: 50%;
  height: 32px;
  width: 32px;
}

.topbar nav,
.actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}

.topbar nav a {
  border-bottom: 2px solid transparent;
  color: var(--ink);
  font-size: 12px;
  padding: 23px 0 21px;
  text-decoration: none;
}

.topbar nav a[aria-current="page"] {
  border-color: var(--ink);
}

.actions {
  font-size: 12px;
  justify-content: flex-end;
}

.actions button,
.note-pill,
.claim-chip,
.source-card button,
.drawer-head button,
.body-copy h2 button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  cursor: pointer;
}

.actions button {
  padding: 8px 13px;
}

.shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr) 382px;
  min-height: calc(100vh - 61px);
}

.toc,
.inspector {
  background: var(--paper);
  height: calc(100vh - 61px);
  overflow: auto;
  position: sticky;
  top: 61px;
}

.toc {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 26px 13px 21px;
}

.rail-label,
.panel-head p {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.16em;
  margin: 0 0 21px;
  text-transform: uppercase;
}

.toc-list {
  display: grid;
  gap: 5px;
}

.toc-row {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 5px;
  grid-template-columns: 28px 1fr;
  padding: 10px 8px;
  text-align: left;
}

.toc-row:hover,
.toc-row[aria-pressed="true"],
.toc-row:focus-visible {
  background: var(--wash);
  border-color: #d8e3d8;
  outline: none;
}

.toc-row span {
  color: var(--blue);
  font-size: 13px;
  grid-row: 1 / span 2;
}

.toc-row b {
  display: block;
  font-size: 12px;
  grid-column: 2;
  line-height: 1.25;
  text-transform: uppercase;
}

.toc-row small {
  color: var(--muted);
  display: block;
  font-size: 11px;
  grid-column: 2;
  line-height: 1.4;
}

.toc-foot {
  border-top: 1px solid var(--line);
  margin-top: auto;
  padding-top: 21px;
}

.toc-foot span {
  background: var(--green);
  border-radius: 50%;
  display: inline-block;
  height: 10px;
  margin-right: 8px;
  width: 10px;
}

.toc-foot p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin: 0;
}

.paper {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.026), transparent 55px),
    var(--paper);
  min-height: calc(100vh - 61px);
}

.manuscript {
  margin: 0 auto;
  max-width: 1040px;
  padding: 68px 42px 64px;
}

.paper-head {
  margin-left: 139px;
  padding-bottom: 42px;
}

.folio {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.12em;
  margin: 0 0 26px;
  text-transform: uppercase;
}

h1 {
  font-family: var(--display);
  font-size: clamp(43px, 5vw, 68px);
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1;
  margin: 0;
}

.dek {
  color: var(--muted);
  font-size: 19px;
  line-height: 1.618;
  margin: 21px 0 0;
  max-width: 710px;
}

.art-panel {
  border-block: 1px solid var(--line);
  margin: 0 0 34px;
  padding: 21px 0;
}

.art-panel img {
  background: var(--paper);
  display: block;
  height: clamp(340px, 46vw, 610px);
  object-fit: cover;
  object-position: center;
  width: 100%;
}

.art-panel figcaption {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  margin: 13px 139px 0;
}

.paper-grid {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 21px;
  grid-template-columns: 118px minmax(0, 1fr);
  padding: 42px 0;
}

.paper-grid::before {
  background: var(--paper);
  color: var(--muted);
  content: attr(data-label);
  display: inline-block;
  font-size: 11px;
  grid-column: 1 / -1;
  letter-spacing: 0.14em;
  padding: 2px 8px 2px 0;
  position: sticky;
  text-transform: uppercase;
  top: 72px;
  width: max-content;
  z-index: 4;
}

.marginal {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.marginal p {
  margin: 0 0 13px;
}

.note-stack,
.claim-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 13px;
}

.note-pill {
  border-color: var(--blue);
  color: var(--blue);
  min-height: 30px;
  min-width: 34px;
  padding: 5px 8px;
}

.note-pill.danger,
.note-pill.danger:hover,
.note-pill.danger:focus-visible {
  border-color: var(--red);
  color: var(--red);
}

.claim-chip {
  color: var(--blue);
  font-family: var(--mono);
  font-size: 11px;
  min-height: 29px;
  padding: 5px 7px;
}

.body-copy {
  font-family: var(--reader);
  font-size: 19px;
  line-height: 1.7;
}

.body-copy h2,
.body-copy h3 {
  font-family: var(--display);
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.12;
  margin: 0 0 18px;
}

.body-copy h2 {
  font-size: 31px;
}

.body-copy h2 button {
  border: 0;
  border-radius: 0;
  font: inherit;
  padding: 0;
  text-align: left;
}

.body-copy h3 {
  font-size: 21px;
  margin-top: 34px;
}

.body-copy p {
  margin: 0 0 21px;
}

.essay-flow,
.essay-backmatter {
  margin-left: 139px;
  max-width: 720px;
}

.essay-section {
  margin: 0;
  padding: 0 0 26px;
  scroll-margin-top: 88px;
}

.essay-section + .essay-section {
  padding-top: 8px;
}

.essay-opening {
  border-block: 1px solid var(--line);
  margin-bottom: 34px;
  padding: 28px 0 8px;
}

.section-kicker {
  color: var(--muted);
  font-family: var(--reader);
  font-size: 11px;
  letter-spacing: 0.13em;
  margin: 0 0 10px;
  text-transform: uppercase;
}

.essay-section h2 {
  margin-top: 0;
}

.inline-figure {
  border-block: 1px solid var(--line);
  font-family: var(--reader);
  margin: 24px 0 8px;
  padding: 18px 0;
}

.inline-figure figcaption {
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
  margin: 0 0 14px;
}

.inline-figure ol {
  counter-reset: figure;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  list-style: none;
  margin: 0;
  padding: 0;
}

.inline-figure li {
  border-top: 1px solid var(--line);
  color: #34342f;
  font-size: 13px;
  line-height: 1.45;
  min-height: 48px;
  padding: 10px 0 0;
}

.inline-figure li::before {
  color: var(--blue);
  content: counter(figure, decimal-leading-zero);
  counter-increment: figure;
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  margin-bottom: 4px;
}

.essay-backmatter {
  border-top: 2px solid var(--ink);
  margin-top: 34px;
  padding-top: 26px;
}

.section-modules,
.doc-block {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 24px;
}

.reader-card,
.switch-card,
.timeline-card,
.diagram-card,
.appendix-card,
.source-card,
.ledger-card,
.inspector-block {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdf6;
}

.reader-card,
.switch-card,
.timeline-card,
.diagram-card {
  font-family: var(--reader);
  font-size: 13px;
  line-height: 1.5;
  padding: 12px;
}

.doc-block {
  border-block: 1px solid var(--line);
  font-family: var(--reader);
  margin: 26px 0;
  padding: 18px 0;
}

.doc-block section {
  border-left: 2px solid var(--line);
  min-width: 0;
  padding-left: 12px;
}

.doc-block h3 {
  color: var(--muted);
  font-family: var(--reader);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.doc-block p {
  font-family: var(--reader);
  font-size: 13px;
  line-height: 1.55;
  margin: 0;
}

.reader-card b,
.switch-card b,
.timeline-card b,
.diagram-card b {
  display: block;
  font-family: var(--reader);
  font-size: 12px;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.reader-card p,
.switch-card p,
.timeline-card p {
  margin: 0;
}

.diagram-card {
  grid-column: 1 / -1;
}

.diagram-card ol {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  list-style: none;
  margin: 0;
  padding: 0;
}

.diagram-card li {
  background: var(--wash);
  border: 1px solid #d8e3d8;
  border-radius: 5px;
  min-height: 44px;
  padding: 10px;
}

.appendix-grid,
.source-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.appendix-card,
.source-card {
  font-family: var(--reader);
  font-size: 13px;
  line-height: 1.45;
  padding: 13px;
}

.appendix-card b {
  display: block;
  margin-bottom: 8px;
}

.appendix-card p,
.source-card p,
.source-card small {
  color: var(--muted);
  display: block;
  margin: 0 0 8px;
}

.appendix-card ul,
.source-gaps {
  margin: 8px 0 0;
  padding-left: 18px;
}

.source-card button {
  border: 0;
  border-radius: 0;
  color: var(--blue);
  font-weight: 700;
  padding: 0;
  text-align: left;
}

.inspector {
  border-left: 1px solid var(--line);
  padding: 26px 21px;
}

.panel-head h2 {
  font-family: var(--display);
  font-size: 24px;
  font-weight: 500;
  line-height: 1.1;
  margin: 0 0 21px;
}

.readout {
  border-block: 1px solid var(--line);
  display: grid;
  gap: 0;
  grid-template-columns: 116px 1fr;
  margin: 0 0 21px;
  padding: 12px 0;
}

.readout dt,
.readout dd {
  border-bottom: 1px solid #ebe8dd;
  font-size: 12px;
  line-height: 1.45;
  margin: 0;
  padding: 8px 0;
}

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

.inspector-block {
  font-size: 13px;
  line-height: 1.55;
  margin-bottom: 10px;
  padding: 13px;
}

.inspector-block h3 {
  font-size: 12px;
  letter-spacing: 0.08em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.inspector-block p {
  margin: 0;
}

.inspector-block a {
  border-bottom: 1px solid var(--line);
  color: var(--blue);
  display: block;
  margin-bottom: 8px;
  padding-bottom: 8px;
  text-decoration: none;
}

.needs-source {
  color: var(--red);
  font-family: var(--mono);
}

.drawer-backdrop {
  background: rgba(12, 12, 10, 0.38);
  inset: 0;
  position: fixed;
  z-index: 20;
}

.claim-drawer {
  background: var(--paper);
  border-left: 1px solid var(--line);
  box-shadow: -24px 0 54px rgba(0, 0, 0, 0.16);
  height: 100vh;
  max-width: min(720px, 92vw);
  overflow: auto;
  padding: 26px;
  position: fixed;
  right: 0;
  top: 0;
  transform: translateX(0);
  transition: transform 160ms ease;
  width: 680px;
  z-index: 30;
}

.claim-drawer[aria-hidden="true"] {
  pointer-events: none;
  transform: translateX(102%);
}

.drawer-head {
  align-items: start;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 18px;
  padding-bottom: 18px;
}

.drawer-head h2 {
  font-family: var(--display);
  font-size: 28px;
  font-weight: 500;
  margin: 0;
}

.drawer-head button {
  padding: 8px 13px;
}

.drawer-body {
  display: grid;
  gap: 10px;
}

.ledger-card {
  padding: 13px;
}

.ledger-card button {
  background: transparent;
  border: 0;
  color: var(--blue);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  padding: 0;
  text-align: left;
}

.ledger-card p {
  font-family: var(--math);
  font-size: 17px;
  line-height: 1.55;
  margin: 8px 0 12px;
}

.ledger-card dl {
  display: grid;
  grid-template-columns: 150px 1fr;
  margin: 0;
}

.ledger-card dt,
.ledger-card dd {
  border-top: 1px solid #ebe8dd;
  font-size: 12px;
  line-height: 1.45;
  margin: 0;
  padding: 8px 0;
}

.ledger-card dt {
  color: var(--muted);
}

[hidden] {
  display: none !important;
}

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

  .inspector {
    grid-column: 1 / -1;
    height: auto;
    position: relative;
    top: auto;
  }
}

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: 1fr;
    padding: 13px 16px;
    position: relative;
  }

  .topbar nav a {
    padding: 0 0 8px;
  }

  .actions {
    justify-content: flex-start;
  }

  .shell {
    display: block;
  }

  .toc,
  .inspector {
    height: auto;
    position: relative;
    top: auto;
  }

  .toc {
    display: none;
  }

  .manuscript {
    padding: 34px 18px 42px;
  }

  .paper-head,
  .art-panel figcaption,
  .essay-flow,
  .essay-backmatter {
    margin-left: 0;
  }

  .paper-grid,
  .section-modules,
  .doc-block,
  .appendix-grid,
  .source-grid {
    grid-template-columns: 1fr;
  }

  .marginal {
    display: grid;
    gap: 8px;
  }

  .diagram-card ol,
  .inline-figure ol {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 540px) {
  h1 {
    font-size: 42px;
  }

  .dek,
  .body-copy {
    font-size: 17px;
  }

  .diagram-card ol,
  .inline-figure ol {
    grid-template-columns: 1fr;
  }

  .claim-drawer {
    max-width: 100vw;
    padding: 18px;
    width: 100vw;
  }

  .ledger-card dl,
  .readout {
    grid-template-columns: 1fr;
  }
}
