:root {
  --bg: #f6f4ee;
  --bg-soft: #eeebe2;
  --paper: #fbfaf6;
  --ink: #171917;
  --ink-soft: #545852;
  --ink-faint: #85887f;
  --line: #d9d5c9;
  --line-strong: #bbb6a9;
  --accent: #3f5f53;
  --accent-ink: #243f36;
  --accent-soft: rgba(63, 95, 83, 0.08);
  --code-bg: #111714;
  --code-ink: #ece9df;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "IBM Plex Sans", "Noto Sans SC", sans-serif;
  --serif: "Newsreader", "Noto Serif SC", serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(23, 25, 23, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, var(--bg) 0%, #faf8f2 42%, var(--bg-soft) 100%);
  background-size: 96px 96px, auto;
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.62;
  text-rendering: optimizeLegibility;
}

body.post-page {
  background:
    linear-gradient(90deg, rgba(23, 25, 23, 0.026) 1px, transparent 1px),
    linear-gradient(180deg, #f8f6f0 0%, #fdfbf7 42%, #f1eee6 100%);
  background-size: 88px 88px, auto;
}

a {
  color: inherit;
  text-decoration: none;
}

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

code,
pre,
.eyebrow,
.site-nav,
.row-meta,
.section-label span,
.archive-stats span,
.document-head span,
.post-meta,
.post-back,
.post-outline-kicker,
.post-pagination-link span {
  font-family: var(--mono);
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 500;
  letter-spacing: -0.03em;
}

p {
  margin: 0;
}

.site-shell {
  width: min(1080px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 0 0 72px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 26px 0 22px;
  border-bottom: 1px solid var(--line);
}

.site-brand {
  font-weight: 700;
  letter-spacing: -0.02em;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 18px;
  color: var(--ink-soft);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.site-nav a {
  position: relative;
}

.site-nav a.active,
.site-nav a:hover {
  color: var(--accent-ink);
}

.site-nav a.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -6px;
  height: 1px;
  background: var(--accent);
}

.eyebrow {
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.index-hero {
  display: grid;
  grid-template-columns: minmax(0, 0.88fr) minmax(320px, 0.62fr);
  gap: 56px;
  align-items: end;
  padding: 112px 0 74px;
}

.index-hero h1 {
  margin-top: 18px;
  font-family: var(--serif);
  font-size: clamp(4rem, 12vw, 9rem);
  line-height: 0.82;
}

.index-claim {
  display: grid;
  gap: 18px;
  padding-bottom: 12px;
  color: var(--ink-soft);
  font-size: clamp(1.08rem, 1.8vw, 1.38rem);
  line-height: 1.55;
}

.index-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line);
}

.index-grid article {
  min-height: 138px;
  padding: 24px 26px 22px 0;
  border-right: 1px solid var(--line);
}

.index-grid article:last-child {
  border-right: 0;
}

.index-grid span {
  display: block;
  margin-bottom: 28px;
  color: var(--ink-faint);
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.index-grid strong {
  display: block;
  max-width: 220px;
  font-size: 1.25rem;
  line-height: 1.25;
}

.index-section,
.archive-section {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 52px;
  padding: 86px 0 0;
}

.section-label {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-label span {
  color: var(--ink-faint);
  font-size: 0.76rem;
}

.section-label h2 {
  font-size: 1rem;
  letter-spacing: 0;
}

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

.index-row,
.archive-row {
  display: grid;
  grid-template-columns: 154px minmax(0, 1fr);
  gap: 30px;
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
}

.index-row:hover,
.archive-row:hover,
.document-list a:hover,
.post-pagination-link:hover {
  background: var(--accent-soft);
}

.row-meta,
.archive-row time {
  color: var(--ink-faint);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.row-main,
.archive-row span {
  display: grid;
  gap: 6px;
}

.row-main strong,
.archive-row strong,
.document-list strong {
  font-size: 1.18rem;
  font-weight: 600;
  line-height: 1.28;
}

.row-main em,
.archive-row em,
.document-list span {
  color: var(--ink-soft);
  font-style: normal;
  line-height: 1.45;
}

.text-link {
  display: inline-flex;
  margin-top: 24px;
  color: var(--accent);
  font-weight: 600;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 36px;
  margin-top: 92px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.94rem;
}

.site-footer p {
  max-width: 620px;
}

.site-footer nav {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  white-space: nowrap;
}

.site-footer code {
  color: var(--accent-ink);
  font-size: 0.9em;
}

.archive-shell {
  width: min(1120px, calc(100vw - 48px));
}

.archive-hero {
  display: grid;
  grid-template-columns: minmax(0, 0.84fr) minmax(320px, 0.58fr);
  gap: 64px;
  align-items: end;
  padding: 92px 0 56px;
}

.archive-hero h1 {
  margin-top: 16px;
  font-family: var(--serif);
  font-size: clamp(3.1rem, 7vw, 6.3rem);
  line-height: 0.94;
}

.archive-hero > p {
  color: var(--ink-soft);
  font-size: 1.15rem;
}

.archive-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line);
}

.archive-stats article {
  padding: 24px 24px 22px 0;
  border-right: 1px solid var(--line);
}

.archive-stats article:last-child {
  border-right: 0;
}

.archive-stats strong {
  display: block;
  font-family: var(--serif);
  font-size: 3rem;
  font-weight: 500;
  line-height: 1;
}

.archive-stats span {
  color: var(--ink-faint);
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

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

.document-group {
  min-width: 0;
}

.document-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line-strong);
}

.document-head h3 {
  font-size: 1.05rem;
}

.document-head span {
  color: var(--ink-faint);
  font-size: 0.75rem;
}

.document-list {
  display: grid;
}

.document-list a {
  display: grid;
  gap: 5px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.document-list strong {
  overflow-wrap: anywhere;
}

.document-list span {
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 0.75rem;
}

.post-shell {
  width: min(1180px, calc(100vw - 48px));
}

.post-topbar {
  margin-bottom: 68px;
}

.post-head {
  max-width: 880px;
  padding-bottom: 50px;
  border-bottom: 1px solid var(--line);
}

.post-back {
  display: inline-flex;
  margin-bottom: 24px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.post-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  color: var(--ink-faint);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.post-head h1 {
  font-family: var(--serif);
  font-size: clamp(2.8rem, 7vw, 5.8rem);
  line-height: 0.98;
}

.post-layout {
  display: grid;
  grid-template-columns: minmax(0, 780px) 240px;
  gap: 76px;
  align-items: start;
  padding-top: 54px;
}

.post-sidebar {
  position: sticky;
  top: 32px;
  max-height: calc(100vh - 64px);
}

.post-outline {
  border-left: 1px solid var(--line);
  padding-left: 18px;
}

.post-outline-kicker {
  margin-bottom: 14px;
  color: var(--ink-faint);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.post-outline-nav {
  display: grid;
  gap: 4px;
  max-height: calc(100vh - 124px);
  overflow: auto;
  padding-right: 4px;
}

.toc-link {
  display: block;
  padding: 6px 0 6px 12px;
  border-left: 2px solid transparent;
  color: var(--ink-soft);
  font-size: 0.86rem;
  line-height: 1.35;
}

.toc-link:hover,
.toc-link.active {
  border-left-color: var(--accent);
  color: var(--accent-ink);
}

.toc-h3 {
  padding-left: 22px;
  font-size: 0.8rem;
}

.toc-h4 {
  padding-left: 34px;
  color: var(--ink-faint);
  font-size: 0.76rem;
}

.post-content {
  min-width: 0;
  color: var(--ink);
  font-size: 1.04rem;
  line-height: 1.78;
}

.post-content > * {
  margin-top: 0;
  margin-bottom: 1.15rem;
}

.post-content > h1:first-child {
  display: none;
}

.post-content h2,
.post-content h3,
.post-content h4 {
  scroll-margin-top: 32px;
}

.post-content h2 {
  margin-top: 4.8rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line-strong);
  font-size: 2rem;
  line-height: 1.15;
}

.post-content h3 {
  margin-top: 2.6rem;
  font-size: 1.42rem;
  line-height: 1.25;
}

.post-content h4 {
  margin-top: 2rem;
  color: var(--ink-soft);
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

.post-content p,
.post-content li,
.post-content blockquote {
  color: var(--ink-soft);
}

.post-content strong {
  color: var(--ink);
  font-weight: 650;
}

.post-content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.post-content ul,
.post-content ol {
  padding-left: 1.35rem;
}

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

.post-content li::marker {
  color: var(--accent);
}

.post-content blockquote {
  margin: 2rem 0;
  padding: 0.2rem 0 0.2rem 1.2rem;
  border-left: 2px solid var(--accent);
}

.post-content hr {
  margin: 3.6rem 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.post-content img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 2rem auto;
  border: 1px solid var(--line);
  background: var(--paper);
}

.post-content code {
  border: 1px solid rgba(63, 95, 83, 0.16);
  border-radius: 5px;
  background: rgba(63, 95, 83, 0.08);
  color: var(--accent-ink);
  font-size: 0.86em;
  padding: 0.1em 0.34em;
}

.post-content pre {
  margin: 1.65rem 0;
  padding: 18px 20px;
  border-radius: 0;
  background: var(--code-bg);
  color: var(--code-ink);
  overflow-x: auto;
  line-height: 1.55;
}

.post-content pre code {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 0.86rem;
}

.post-content table {
  display: block;
  width: 100%;
  margin: 2rem 0;
  border-collapse: collapse;
  overflow-x: auto;
  font-size: 0.93rem;
}

.post-content th,
.post-content td {
  padding: 0.72rem 0.8rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.post-content th {
  color: var(--ink);
  font-weight: 650;
}

.post-content td {
  color: var(--ink-soft);
}

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

.post-content mjx-container[display="true"] {
  margin: 1.75rem 0 !important;
  padding: 0.35rem 0;
}

.post-pagination {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 5rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--line-strong);
}

.post-pagination-link {
  display: grid;
  gap: 8px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.post-pagination-link span {
  color: var(--ink-faint);
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.post-pagination-link strong {
  font-weight: 600;
  line-height: 1.32;
}

.post-pagination-next {
  text-align: right;
}

@media (max-width: 900px) {
  .site-shell,
  .archive-shell,
  .post-shell {
    width: min(100% - 32px, 760px);
  }

  .site-header,
  .site-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .index-hero,
  .archive-hero,
  .index-section,
  .archive-section,
  .post-layout {
    grid-template-columns: 1fr;
  }

  .index-hero {
    gap: 36px;
    padding: 76px 0 54px;
  }

  .archive-hero {
    gap: 26px;
    padding: 68px 0 42px;
  }

  .index-grid,
  .archive-stats,
  .document-grid {
    grid-template-columns: 1fr;
  }

  .index-grid article,
  .archive-stats article {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .index-grid article:last-child,
  .archive-stats article:last-child {
    border-bottom: 0;
  }

  .index-section,
  .archive-section {
    gap: 22px;
    padding-top: 62px;
  }

  .section-label {
    flex-direction: row;
    align-items: baseline;
  }

  .post-topbar {
    margin-bottom: 44px;
  }

  .post-head {
    padding-bottom: 36px;
  }

  .post-layout {
    gap: 28px;
    padding-top: 36px;
  }

  .post-sidebar {
    position: static;
    order: -1;
    max-height: none;
  }

  .post-outline {
    border-left: 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    padding: 14px 0;
  }

  .post-outline-nav {
    max-height: 220px;
  }
}

@media (max-width: 620px) {
  body {
    background-size: 64px 64px, auto;
  }

  .site-nav {
    gap: 12px;
    font-size: 0.72rem;
  }

  .index-hero h1 {
    font-size: clamp(3.8rem, 22vw, 5.4rem);
  }

  .index-claim,
  .archive-hero > p {
    font-size: 1rem;
  }

  .index-row,
  .archive-row {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 20px 0;
  }

  .site-footer nav {
    white-space: normal;
  }

  .post-head h1 {
    font-size: clamp(2.5rem, 14vw, 4rem);
  }

  .post-content {
    font-size: 1rem;
  }

  .post-content h2 {
    font-size: 1.7rem;
  }

  .post-content h3 {
    font-size: 1.28rem;
  }

  .post-content pre {
    margin-left: -16px;
    margin-right: -16px;
    border-radius: 0;
  }

  .post-content th,
  .post-content td {
    padding: 0.62rem;
  }

  .post-pagination {
    grid-template-columns: 1fr;
  }

  .post-pagination-next {
    text-align: left;
  }
}
