:root {
  color-scheme: dark;
  --background: #000;
  --text: #f5f5f5;
  --secondary: #a3a3a3;
  --faint: #555;
  --line: #242424;
  --width: 720px;
  --signature-filter: invert(1);
}

:root[data-theme="light"] {
  color-scheme: light;
  --background: #fff;
  --text: #111;
  --secondary: #555;
  --faint: #999;
  --line: #ddd;
  --signature-filter: none;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color 180ms ease, color 180ms ease;
}

a {
  color: inherit;
  text-decoration-color: var(--faint);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  transition: text-decoration-color 160ms ease;
}

a:hover,
a:focus-visible {
  text-decoration-color: currentColor;
}

.page {
  width: min(calc(100% - 40px), var(--width));
  margin: 0 auto;
  padding: 48px 0 64px;
}

.home-page {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px;
  color: var(--secondary);
  font-size: 14px;
}

.site-nav a {
  text-decoration: none;
}

.site-nav a[aria-current="page"] {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--faint);
}

.theme-toggle {
  position: fixed;
  top: 24px;
  right: 28px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--secondary);
  background: var(--background);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: color 160ms ease, border-color 160ms ease, background-color 180ms ease, transform 160ms ease;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  color: var(--text);
  border-color: var(--secondary);
  transform: rotate(12deg);
  outline: none;
}

.home-hero {
  margin: auto 0;
  padding: 80px 0 120px;
}

.page-header {
  margin: 110px 0 80px;
}

h1 {
  margin: 0 0 27px;
  font-size: clamp(38px, 7vw, 56px);
  line-height: 1;
  letter-spacing: -0.055em;
  font-weight: 600;
}

.intro,
.page-header p {
  max-width: 690px;
  margin: 0 0 18px;
  color: var(--secondary);
  font-size: clamp(19px, 3vw, 23px);
  line-height: 1.5;
  letter-spacing: -0.015em;
}

.intro strong {
  color: var(--text);
  font-weight: 500;
}

.inline-chip {
  display: inline-block;
  padding: 0 5px;
  border-radius: 4px;
  color: var(--text);
  text-decoration: none;
  background: color-mix(in srgb, var(--line) 45%, var(--background));
  transition: background-color 160ms ease, text-decoration-color 160ms ease;
}

.inline-chip:hover,
.inline-chip:focus-visible {
  background: color-mix(in srgb, var(--line) 62%, var(--background));
  text-decoration: underline;
  text-decoration-color: var(--faint);
}

.links {
  margin-top: 30px;
  color: var(--secondary);
  font-size: 15px;
}

.links span {
  padding: 0 7px;
  color: var(--faint);
}

section {
  margin-top: 60px;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 12px;
}

h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.section-note {
  color: var(--faint);
  font-size: 13px;
}

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

.item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 32px;
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
}

.item-main {
  min-width: 0;
}

.item-title {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 17px;
  font-weight: 500;
  text-decoration: none;
}

a.item-title:hover,
a.item-title:focus-visible {
  text-decoration: underline;
}

.item-copy {
  max-width: 570px;
  margin: 0;
  color: var(--secondary);
  font-size: 14px;
  line-height: 1.55;
}

.item-meta {
  padding-top: 3px;
  color: var(--faint);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.reading-library {
  margin-top: 42px;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 18px;
  align-items: start;
}

.book-tile {
  position: relative;
  min-width: 0;
}

.book-tile-link {
  position: relative;
  display: block;
  color: inherit;
  text-decoration: none;
  outline: none;
  transform-origin: center top;
  transition: transform 160ms ease, filter 160ms ease;
}

.book-tile-link:hover,
.book-tile-link:focus-visible {
  z-index: 5;
  filter: saturate(1.08);
  transform: scale(1.12);
}

.book-cover {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--line);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), transparent 42%),
    color-mix(in srgb, var(--line) 82%, var(--background));
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.book-tile-link:hover .book-cover,
.book-tile-link:focus-visible .book-cover {
  border-color: var(--secondary);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.34);
}

.book-cover img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-cover span {
  z-index: 1;
  padding: 0 12px;
  color: var(--secondary);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 17px;
  letter-spacing: 0;
  text-align: center;
}

.book-cover:not(.book-cover--missing) span {
  opacity: 0;
}

.book-tile-panel {
  position: absolute;
  right: -10px;
  bottom: 10px;
  left: -10px;
  z-index: 2;
  padding: 10px;
  border: 1px solid var(--line);
  color: var(--text);
  background: color-mix(in srgb, var(--background) 92%, transparent);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease, border-color 160ms ease;
}

.book-tile-link:hover .book-tile-panel,
.book-tile-link:focus-visible .book-tile-panel {
  border-color: var(--secondary);
  opacity: 1;
  transform: translateY(0);
}

.book-tile-status {
  margin-bottom: 5px;
  color: var(--faint);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  text-transform: uppercase;
}

.book-tile-panel h3,
.book-tile-panel p {
  margin: 0;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
}

.book-tile-panel h3 {
  color: var(--text);
  font-size: 12px;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: 0;
  -webkit-line-clamp: 2;
}

.book-tile-panel p {
  margin-top: 4px;
  color: var(--secondary);
  font-size: 11px;
  line-height: 1.3;
  -webkit-line-clamp: 1;
}

.result {
  color: var(--text);
}

.back-link {
  display: inline-block;
  margin-top: 54px;
  color: var(--faint);
  font-size: 13px;
}

.article-header {
  margin: 58px 0 56px;
}

.article-meta {
  margin: -12px 0 22px;
  color: var(--faint);
  font-size: 13px;
}

.article-body {
  color: var(--secondary);
  font-size: 15px;
  line-height: 1.72;
}

.article-body h2 {
  margin: 54px 0 14px;
  color: var(--text);
  font-size: 19px;
}

.article-body h3 {
  margin: 30px 0 10px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.article-body p,
.article-body ul,
.article-body ol {
  margin: 0 0 18px;
}

.article-body ul,
.article-body ol {
  padding-left: 22px;
}

.article-body li {
  margin-bottom: 8px;
}

.article-body strong {
  color: var(--text);
  font-weight: 500;
}

.article-body code {
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
}

.article-body pre {
  overflow-x: auto;
  max-width: 100%;
  margin: 26px 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  color: var(--text);
  background: color-mix(in srgb, var(--line) 34%, var(--background));
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  -webkit-overflow-scrolling: touch;
}

.article-body pre code {
  display: block;
  width: max-content;
  min-width: 100%;
  padding: 0;
  color: inherit;
  background: transparent;
  font-size: inherit;
  line-height: inherit;
  white-space: pre;
}

.article-body table {
  display: block;
  width: 100%;
  overflow-x: auto;
  margin: 24px 0;
  border-collapse: collapse;
  font-size: 13px;
}

.article-body th,
.article-body td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.article-body th {
  color: var(--text);
  font-weight: 500;
}

.article-body .formula {
  white-space: pre-wrap;
}

.shard-page {
  --width: 46rem;
}

.shard-writeup {
  margin-top: 32px;
}

.shard-writeup h1 {
  margin-bottom: 12px;
  font-size: clamp(32px, 5vw, 44px);
  line-height: 1.08;
}

.shard-writeup .meta {
  margin: 0 0 54px;
  color: var(--faint);
  font-size: 13px;
}

.shard-writeup .big-num {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.shard-writeup sup a {
  color: var(--faint);
  font-size: 0.82em;
  text-decoration: none;
}

.shard-writeup .katex {
  font-size: 1em !important;
}

.shard-writeup .katex-display {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  margin: 22px 0;
  padding: 6px 0;
  -webkit-overflow-scrolling: touch;
}

.shard-writeup .katex-display > .katex {
  white-space: nowrap;
}

.shard-writeup .diagram {
  overflow-x: auto;
  margin: 24px 0;
  padding: 16px;
  border: 1px solid var(--line);
  color: var(--secondary);
  background: color-mix(in srgb, var(--line) 24%, var(--background));
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
  -webkit-overflow-scrolling: touch;
}

.shard-writeup .profile-figure {
  margin: 28px 0;
  padding: 18px;
  border: 1px solid var(--line);
}

.shard-writeup .profile-figure h3 {
  margin-top: 0;
}

.shard-writeup .profile-bars {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.shard-writeup .profile-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(120px, 2fr) 72px;
  gap: 12px;
  align-items: center;
  font-size: 12px;
}

.shard-writeup .profile-label {
  color: var(--text);
  font-weight: 500;
}

.shard-writeup .profile-value {
  color: var(--secondary);
  font-family: "SFMono-Regular", Consolas, monospace;
  text-align: right;
}

.shard-writeup .track {
  height: 7px;
  overflow: hidden;
  background: color-mix(in srgb, var(--line) 72%, var(--background));
}

.shard-writeup .bar {
  height: 100%;
  background: var(--secondary);
}

.shard-writeup .bar.good {
  background: var(--text);
}

.shard-writeup .profile-caption {
  margin: 16px 0 0;
  color: var(--secondary);
  font-size: 13px;
  font-style: italic;
}

.shard-writeup .muted,
.shard-writeup .footnotes {
  color: var(--secondary);
  font-size: 13px;
}

.shard-writeup .footnotes h3 {
  font-size: 15px;
}

.experience .item {
  grid-template-columns: 155px 1fr;
}

.experience .item-meta {
  order: -1;
}

footer {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin-top: 110px;
  color: var(--faint);
  font-size: 12px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 24px;
  width: 100%;
}

.footer-signoff {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  width: 100%;
  color: var(--faint);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
}

.footer-signoff span {
  white-space: nowrap;
}

.footer-signoff img {
  display: block;
  justify-self: end;
  width: 72px;
  height: 45px;
  object-fit: contain;
  opacity: 0.72;
  filter: var(--signature-filter);
}

.home-signoff {
  margin-top: auto;
}

@media (max-width: 620px) {
  .page {
    width: min(calc(100% - 32px), var(--width));
    padding-top: 28px;
  }

  .site-nav {
    gap: 16px;
    padding-right: 48px;
  }

  .theme-toggle {
    top: 18px;
    right: 18px;
  }

  .home-hero {
    padding-bottom: 76px;
  }

  .page-header {
    margin: 82px 0 62px;
  }

  .section-heading,
  footer {
    align-items: flex-start;
  }

  .footer-links {
    gap: 18px;
  }

  .footer-signoff img {
    width: 64px;
    height: 40px;
  }

  .item,
  .experience .item {
    grid-template-columns: 1fr;
    gap: 11px;
  }

  .book-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px 14px;
  }

  .experience .item-meta {
    order: initial;
  }
}

@media (max-width: 380px) {
  .book-grid {
    grid-template-columns: 1fr;
  }
}

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

  * {
    transition-duration: 0.01ms !important;
  }
}
