:root {
  color-scheme: light;
  --bg: #f7f2e8;
  --ink: #171512;
  --muted: #746d61;
  --line: #d8ccba;
  --soft: #efe6d7;
  --link: #3e3a33;
  --missing: #8a4b3f;
  --code-bg: #ebe0d0;
  --footer-control-lift: 2.25rem;
  --max: 760px;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Source Serif 4", Georgia, Cambria, "Times New Roman", serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151412;
  --ink: #eee7dc;
  --muted: #aaa194;
  --line: #37312a;
  --soft: #1f1d19;
  --link: #f2e4ca;
  --missing: #d09583;
  --code-bg: #25221e;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #151412;
    --ink: #eee7dc;
    --muted: #aaa194;
    --line: #37312a;
    --soft: #1f1d19;
    --link: #f2e4ca;
    --missing: #d09583;
    --code-bg: #25221e;
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
}

a {
  color: var(--link);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  text-decoration-style: wavy;
}

button,
summary {
  font: inherit;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: 1rem;
  z-index: 20;
  transform: translateY(-150%);
  background: var(--ink);
  color: var(--bg);
  padding: 0.45rem 0.65rem;
  font-family: var(--mono);
  font-size: 0.78rem;
}

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

.progress {
  position: fixed;
  inset: 0 0 auto;
  height: 2px;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: 0 50%;
  z-index: 15;
}

.site-header,
.site-footer {
  align-items: center;
  gap: 1rem;
  max-width: 1180px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}

.site-header {
  display: grid;
  grid-template-columns: auto auto minmax(12rem, 26rem) auto;
  border-bottom: 1px solid var(--line);
}

.site-footer {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

.identity {
  display: inline-flex;
  align-items: baseline;
  gap: 0.55rem;
  color: var(--ink);
  text-decoration: none;
}

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

.identity strong {
  font-weight: 400;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.8rem;
}

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

.site-search {
  position: relative;
  align-self: center;
  width: min(100%, 26rem);
  justify-self: end;
}

.site-search-input {
  width: 100%;
  height: 2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.76rem;
  padding: 0 0.85rem;
}

.site-search-input:focus {
  background: var(--bg);
  outline: 1px solid var(--ink);
  outline-offset: 2px;
}

.site-search-results {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  z-index: 40;
  width: min(24rem, calc(100vw - 2rem));
  max-height: min(28rem, calc(100vh - 6rem));
  overflow: auto;
  padding: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.12);
}

.search-results-label {
  padding: 0.25rem 0.35rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.68rem;
  text-transform: uppercase;
}

.search-result,
.search-memory-item,
.search-suggestion {
  width: 100%;
  display: block;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  text-decoration: none;
}

.search-result {
  padding: 0.55rem 0.6rem;
}

.search-result span {
  display: block;
  font-size: 0.86rem;
  line-height: 1.3;
}

.search-result small {
  display: block;
  margin-top: 0.12rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.66rem;
}

.search-result p {
  margin: 0.22rem 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.35;
}

.search-memory-item,
.search-suggestion,
.search-empty {
  padding: 0.48rem 0.55rem;
  font-family: var(--mono);
  font-size: 0.74rem;
}

.search-suggestion strong {
  font-weight: 400;
  color: var(--ink);
}

.search-empty {
  margin: 0;
  color: var(--muted);
}

.search-result:hover,
.search-result:focus-visible,
.search-memory-item:hover,
.search-memory-item:focus-visible,
.search-suggestion:hover,
.search-suggestion:focus-visible {
  background: var(--soft);
  outline: none;
}

.mobile-menu,
.theme-toggle {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-family: var(--mono);
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
}

.mobile-menu {
  display: none;
  width: 2rem;
  height: 2rem;
  padding: 0;
}

.mobile-menu svg {
  display: block;
}

.mobile-close {
  display: none;
}

.mobile-menu:hover,
.mobile-menu:focus-visible,
.theme-toggle:hover,
.theme-toggle:focus-visible {
  background: var(--soft);
  outline: none;
}

.theme-toggle span {
  display: block;
  transform: translateY(-1px);
}

.shell {
  display: grid;
  grid-template-columns: 260px minmax(0, var(--max)) 220px;
  max-width: 1440px;
  justify-content: center;
  gap: 2rem;
  margin: 0 auto;
  padding: 1.4rem 1.25rem 2rem;
}

body.nav-collapsed .shell {
  grid-template-columns: 260px minmax(0, var(--max)) 220px;
  max-width: 1440px;
}

body.notes-collapsed .shell {
  grid-template-columns: 260px minmax(0, var(--max)) 220px;
  max-width: 1440px;
}

body.nav-collapsed.notes-collapsed .shell {
  grid-template-columns: 260px minmax(0, var(--max)) 220px;
  max-width: 1440px;
}

body.nav-collapsed .sidebar-inner,
body.notes-collapsed .page-meta-inner {
  display: none;
}

body.nav-collapsed .sidebar,
body.notes-collapsed .page-meta {
  overflow: visible;
}

.sidebar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.sidebar,
.page-meta {
  position: sticky;
  top: 1rem;
  align-self: start;
  max-height: calc(100vh - 2rem);
  overflow: auto;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--muted);
  border-left: 0;
}

.page-meta {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.rail-toggle {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: 0.85rem;
  margin-left: auto;
  padding: 0;
}

.rail-toggle:hover,
.rail-toggle:focus-visible {
  background: var(--soft);
  color: var(--ink);
  outline: none;
}

.rail-toggle svg {
  display: block;
}

.notes-toggle {
  margin-left: 0;
  margin-right: auto;
}

body.nav-collapsed .sidebar .rail-toggle,
body.notes-collapsed .notes-toggle {
  transform: rotate(180deg);
}

.sidebar-label {
  margin-bottom: 0.7rem;
  color: var(--muted);
}

.nav-home {
  display: block;
  color: var(--ink);
  margin-bottom: 0.7rem;
}

.current-page {
  margin: 0 0 0.9rem;
  padding: 0.65rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  line-height: 1.45;
}

.current-page strong {
  color: var(--ink);
  font-weight: 400;
}

details {
  border-top: 1px solid var(--line);
}

summary {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.58rem 0;
  cursor: pointer;
  color: var(--ink);
  list-style: none;
}

.toggle-symbol {
  display: none !important;
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: "+";
  color: var(--muted);
  font-family: var(--mono);
}

details[open] > summary::after {
  content: "-";
  color: var(--ink);
}

summary span {
  color: var(--muted);
}

nav ol {
  list-style: decimal-leading-zero;
  margin: 0 0 0.85rem 1.45rem;
  padding: 0;
}

nav li {
  margin: 0.25rem 0;
  padding-left: 0.2rem;
}

nav a {
  color: var(--muted);
}

nav a[aria-current="page"] {
  color: var(--ink);
  text-decoration: none;
}

.page-contents {
  margin-bottom: 1.2rem;
}

.page-contents a {
  border-radius: 4px;
  display: inline-block;
  padding: 0.04rem 0.18rem;
}

.page-contents a[aria-current="true"] {
  background: var(--soft);
  color: var(--ink);
  text-decoration: none;
}

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

.toc-list li {
  margin: 0.24rem 0;
  padding-left: 0;
}

.toc-list .toc-sub {
  padding-left: 0.85rem;
}

.toc-list .toc-sub a {
  color: var(--muted);
}

.browse-wiki {
  margin-top: 1rem;
}

.browse-wiki summary {
  font-size: 0.78rem;
}

.priority-nav summary {
  color: var(--ink);
}

.priority-nav ol {
  border-left: 1px solid var(--line);
  margin-left: 0.45rem;
  padding-left: 1.1rem;
}

.empty-note {
  margin: 0;
  color: var(--muted);
}

.content {
  min-width: 0;
}

.concept-popover-close {
  display: inline-grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.concept-popover-close:hover,
.concept-popover-close:focus-visible {
  background: var(--soft);
  color: var(--ink);
  outline: none;
}

.learner-aid {
  margin: 0 0 1rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
}

.learner-aid summary {
  padding: 0.55rem 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}

.learner-aid[open] summary {
  color: var(--ink);
}

.learner-aid p,
.learner-aid ul {
  margin: 0 0 0.8rem;
}

.learner-aid div {
  margin: 0.65rem 0;
}

.learner-aid div span,
.first-aid-prompt {
  color: var(--muted);
}

.learner-aid ul {
  padding-left: 1.2rem;
}

.syllabus-note {
  margin: 0 0 1rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
}

.page-meta .syllabus-note {
  margin-top: 0.9rem;
  margin-bottom: 0;
}

.syllabus-note summary {
  padding: 0.55rem 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}

.syllabus-note[open] summary {
  color: var(--ink);
}

.syllabus-note p {
  margin: 0 0 0.8rem;
  color: var(--muted);
}

.article {
  font-family: var(--serif);
  font-size: 1.08rem;
}

.article h1,
.article h2,
.article h3,
.article h4,
.article h5,
.article h6 {
  font-family: var(--sans);
  font-weight: 500;
  line-height: 1.22;
  margin: 2.1rem 0 0.7rem;
}

.article h1 {
  margin-top: 0;
  font-size: clamp(2rem, 5vw, 3.4rem);
  letter-spacing: 0;
}

.article h2 {
  font-size: 1.38rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.article h3 {
  font-size: 1.08rem;
}

.article p,
.article ul,
.article ol,
.article blockquote,
.article pre {
  margin: 0.8rem 0;
}

.article ul,
.article ol {
  padding-left: 1.4rem;
}

.article li + li {
  margin-top: 0.25rem;
}

.article hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1.4rem 0;
}

.article code {
  background: var(--code-bg);
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 0.08rem 0.22rem;
  overflow-wrap: anywhere;
}

.article pre {
  overflow: auto;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.85rem;
}

.article pre code {
  background: transparent;
  padding: 0;
  overflow-wrap: normal;
}

mjx-container {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

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

.technical-section {
  margin: 1.4rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.technical-section summary {
  padding: 0.8rem 0;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
}

.technical-section[open] summary {
  color: var(--ink);
}

.missing-link {
  color: var(--missing);
  text-decoration: underline dotted;
  text-underline-offset: 0.18em;
}

.concept-link {
  text-decoration-style: dotted;
}

.concept-popover[hidden] {
  display: none;
}

body.concept-open {
  overflow: hidden;
}

.concept-popover {
  position: fixed;
  inset: 0;
  z-index: 45;
}

.concept-popover-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 21, 18, 0.26);
}

.concept-popover-panel {
  position: absolute;
  right: 1rem;
  top: 1rem;
  bottom: 1rem;
  width: min(30rem, calc(100vw - 2rem));
  overflow: auto;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.18);
  animation: panel-in 160ms ease-out both;
}

.concept-popover-close {
  float: right;
  margin-left: 0.75rem;
}

.concept-popover h2 {
  margin: 0 2.2rem 0.7rem 0;
  font-size: 1.2rem;
  font-weight: 500;
  line-height: 1.25;
}

.concept-popover-body {
  font-family: var(--serif);
  font-size: 1rem;
}

.concept-popover-body h1 {
  display: none;
}

.concept-popover-body h2 {
  clear: both;
  margin: 1rem 0 0.35rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 0.92rem;
}

.concept-popover-body p,
.concept-popover-body ul {
  margin: 0.6rem 0;
}

.concept-popover-link {
  display: inline-block;
  margin-top: 0.8rem;
  font-family: var(--mono);
  font-size: 0.76rem;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateX(0.6rem);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.topic-footer-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  margin: 2rem 0 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
}

.topic-nav-link {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-height: 0;
  padding: 0.58rem 0.65rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-decoration: none;
  color: var(--ink);
  text-overflow: ellipsis;
}

.topic-nav-direction {
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.1;
  text-transform: uppercase;
}

.topic-nav-link strong {
  display: block;
  font-weight: 400;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topic-nav-next {
  text-align: right;
}

.topic-nav-link:hover,
.topic-nav-link:focus-visible {
  background: var(--soft);
  outline: none;
}

.meta-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 0.7rem;
  margin: 0;
}

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

.meta-list dd {
  margin: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.page-meta details {
  margin-top: 0.9rem;
}

.page-meta p {
  margin: 0.5rem 0 0;
}

.page-meta ol {
  margin: 0 0 0.85rem 1.25rem;
  padding: 0;
}

.page-meta li {
  margin: 0.35rem 0;
  overflow-wrap: anywhere;
}

.top-link {
  position: fixed;
  right: 2rem;
  bottom: 2rem;
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 1.2rem;
  text-decoration: none;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
  transition: transform 160ms ease;
  z-index: 20;
}

.top-link:hover,
.top-link:focus-visible {
  transform: translateY(0);
}

body.controls-near-footer .top-link {
  transform: translateY(calc(-1 * var(--footer-control-lift)));
}

.mobile-notes-details > summary {
  display: none;
}
.mobile-notes-details:not([open]) > :not(summary) {
  display: block;
}

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

@media (max-width: 1250px) {
  .mobile-menu {
    display: inline-grid;
    place-items: center;
    background: var(--bg);
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    z-index: 50;
    width: 3rem;
    height: 3rem;
    font-size: 1.2rem;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    transition: transform 160ms ease;
  }

  body.nav-open .mobile-menu,
  .mobile-menu:hover,
  .mobile-menu:focus-visible {
    transform: translateY(0);
  }

  body.controls-near-footer:not(.nav-open) .mobile-menu {
    transform: translateY(calc(-1 * var(--footer-control-lift)));
  }

  .mobile-notes-details > summary {
    display: flex;
  }
  .mobile-notes-details:not([open]) > :not(summary) {
    display: none;
  }

  .site-header {
    grid-template-columns: auto 1fr auto;
  }

  .site-search {
    width: 100%;
    justify-self: stretch;
  }

  .site-search-results {
    left: 0;
    right: auto;
    width: min(100%, calc(100vw - 2rem));
  }

  .shell {
    grid-template-columns: minmax(0, 1fr);
    max-width: 1180px;
    padding: 1.4rem 1.25rem 2rem;
  }

  .page-meta {
    position: static;
    max-height: none;
    width: 100%;
    margin-left: 0;
  }

  .sidebar {
    position: fixed;
    top: 0;
    right: auto;
    bottom: 0;
    left: -100%;
    z-index: 30;
    width: min(84vw, 21rem);
    max-height: none;
    height: 100vh;
    padding: 1rem 1rem 2rem;
    background: var(--bg);
    border-right: 1px solid var(--line);
    opacity: 1;
    transform: none;
    transition: left 160ms ease;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.08);
    pointer-events: none;
  }

  .mobile-close {
    display: inline-grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    margin-left: auto;
    margin-bottom: 1rem;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
  }

  .mobile-close:hover,
  .mobile-close:focus-visible {
    background: var(--soft);
    color: var(--ink);
    outline: none;
  }

  .mobile-close svg {
    display: block;
  }

  body.nav-open #site-sidebar.sidebar {
    left: 0 !important;
    transform: none !important;
    pointer-events: auto;
  }

  body.nav-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(23, 21, 18, 0.22);
  }

  .sidebar-inner,
  body.nav-collapsed .sidebar-inner,
  body.notes-collapsed .page-meta-inner {
    display: block;
  }

  .rail-toggle {
    display: none;
  }

  .page-meta {
    border-top: 1px solid var(--line);
    padding-top: 1rem;
  }

  body.nav-collapsed .shell,
  body.notes-collapsed .shell,
  body.nav-collapsed.notes-collapsed .shell {
    grid-template-columns: minmax(0, 1fr);
    max-width: 1180px;
  }
}

@media (max-width: 640px) {
  .site-header {
    grid-template-columns: auto 1fr auto;
  }

  .shell,
  .site-header,
  .site-footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .article {
    font-size: 1rem;
  }

  .topic-footer-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
    font-size: 0.68rem;
  }

  .topic-nav-link {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
    min-height: 0;
    overflow: hidden;
    padding: 0.46rem 0.5rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topic-nav-next {
    text-align: right;
    flex-direction: row-reverse;
  }

  .topic-nav-direction {
    flex: 0 0 auto;
    font-size: 0.62rem;
  }

  .topic-nav-word {
    display: inline;
  }

  .topic-nav-link strong {
    display: inline;
    min-width: 0;
    font-size: 0.72rem;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .concept-popover-panel {
    inset: auto 0 0;
    width: 100%;
    max-height: 78vh;
    border-radius: 8px 8px 0 0;
  }

}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
