:root {
  --bg: #f3f6f2;
  --paper: #fffefa;
  --paper-soft: #e7ece7;
  --ink: #181713;
  --muted: #6f6a5f;
  --line: rgba(32, 42, 35, 0.14);
  --accent: #b23b2f;
  --accent-dark: #6f271f;
  --code: #101614;
  --shadow: 0 24px 70px rgba(22, 34, 27, 0.12);
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", "Noto Serif SC", "Songti SC", serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: 18px;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  background:
    linear-gradient(90deg, rgba(32, 42, 35, 0.055) 1px, transparent 1px),
    linear-gradient(180deg, #fbfcfa 0%, var(--bg) 38%, #e8eeeb 100%);
  background-size: 72px 72px, auto;
}

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

.site-hero {
  padding: 22px clamp(18px, 4vw, 56px) 48px;
}

.topbar,
.hero-grid,
.reader-shell {
  width: min(1200px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  font-family: var(--sans);
  font-size: 0.86rem;
}

.topbar div {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.brand,
.topbar a:not(.brand),
.hero-actions a {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.72);
}

.brand {
  padding: 9px 13px;
  font-weight: 800;
}

.topbar a:not(.brand),
.hero-actions a {
  padding: 9px 12px;
  color: var(--muted);
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 430px);
  gap: 32px;
  align-items: end;
  padding-top: 86px;
}

.eyebrow,
.toc-title,
.source-note {
  margin: 0;
  color: var(--accent);
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hero-copy h1 {
  margin: 14px 0 0;
  max-width: 13ch;
  font-size: clamp(2.8rem, 7vw, 5.9rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.lead {
  max-width: 720px;
  margin: 24px 0 0;
  color: #4e493f;
  font-size: clamp(1.05rem, 2vw, 1.28rem);
  line-height: 1.85;
}

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 30px;
  font-family: var(--sans);
}

.hero-actions .primary-action {
  border-color: transparent;
  background: var(--ink);
  color: #fffaf0;
}

.pattern-panel {
  margin: 0;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #15211e;
  color: #fbfff6;
  box-shadow: var(--shadow);
}

.pattern-panel p {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.08rem;
  line-height: 1.75;
}

.pattern-panel span {
  display: block;
  margin-top: 22px;
  color: #c4d0c7;
  line-height: 1.7;
}

.reader-shell {
  display: grid;
  grid-template-columns: 270px minmax(0, 820px);
  gap: 52px;
  align-items: start;
  padding: 18px clamp(18px, 4vw, 56px) 80px;
}

.toc {
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 36px);
  padding: 18px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.74);
  backdrop-filter: blur(10px);
}

.toc-title {
  margin-bottom: 12px;
}

.toc-links {
  display: grid;
  gap: 6px;
}

.toc-links a {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 8px;
  align-items: baseline;
  padding: 8px 6px;
  border-radius: 6px;
  color: #3e3a32;
  font-family: var(--sans);
  font-size: 0.82rem;
  line-height: 1.35;
}

.toc-links a:hover,
.toc-links a.is-active {
  background: #e5ece6;
  color: var(--accent-dark);
}

.toc-links span {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.article {
  min-width: 0;
  padding: 38px clamp(20px, 4vw, 62px) 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.source-note {
  margin-bottom: 30px;
  letter-spacing: 0;
  text-transform: none;
}

.source-note a,
.article a {
  color: var(--accent-dark);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

.article h1,
.article h2,
.article h3,
.article h4 {
  margin: 0;
  scroll-margin-top: 28px;
  line-height: 1.25;
  letter-spacing: 0;
}

.article h1 {
  margin-bottom: 26px;
  font-size: clamp(2.1rem, 5vw, 3.4rem);
}

.article h2 {
  margin-top: 64px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
  font-size: clamp(1.55rem, 3vw, 2.2rem);
}

.article h3 {
  margin-top: 38px;
  font-size: 1.28rem;
}

.article h4 {
  margin-top: 30px;
  font-size: 1.05rem;
}

.article p,
.article li,
.article blockquote {
  line-height: 1.92;
}

.article p {
  margin: 18px 0 0;
}

.article ul,
.article ol {
  margin: 18px 0 0;
  padding-left: 1.35em;
}

.article li + li {
  margin-top: 8px;
}

.article blockquote {
  margin: 24px 0;
  padding: 16px 20px;
  border-left: 4px solid var(--accent);
  background: #eef3ed;
}

.article blockquote p {
  margin: 0;
}

.article code {
  padding: 0.12em 0.34em;
  border-radius: 4px;
  background: #e7ece7;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
}

.code-block {
  margin: 26px 0;
  overflow: hidden;
  border-radius: 8px;
  background: var(--code);
  color: #f4f1e8;
}

.code-block figcaption {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  color: #bbb3a1;
  font-family: var(--sans);
  font-size: 0.78rem;
}

.code-block pre {
  margin: 0;
  padding: 18px;
  overflow: auto;
  font-size: 0.86rem;
  line-height: 1.7;
}

.code-block code {
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
}

.table-wrap {
  width: 100%;
  margin: 24px 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.9rem;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--paper-soft);
  font-weight: 800;
}

tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 900px) {
  html {
    font-size: 17px;
  }

  .site-hero {
    padding: 14px 12px 26px;
  }

  .topbar {
    align-items: flex-start;
  }

  .hero-grid {
    grid-template-columns: 1fr;
    padding-top: 48px;
  }

  .hero-copy h1 {
    max-width: 9ch;
  }

  .reader-shell {
    display: block;
    padding: 0 12px 50px;
  }

  .toc {
    position: relative;
    top: auto;
    max-height: none;
    margin-bottom: 14px;
  }

  .toc-links {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .toc-links a {
    min-width: 220px;
  }

  .article {
    padding: 26px 18px 42px;
  }
}

@media (max-width: 520px) {
  .topbar,
  .topbar div,
  .hero-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar a,
  .hero-actions a {
    text-align: center;
  }

  .hero-copy h1 {
    font-size: 2.55rem;
  }

  .pattern-panel {
    padding: 20px;
  }
}
