:root {
  color-scheme: light;
  --bg: #f5f2ea;
  --paper: #fffdfa;
  --paper-soft: #f9f3e7;
  --ink: #1f2422;
  --muted: #66706a;
  --line: #ded6c8;
  --green: #1e6f5c;
  --blue: #2f5f8f;
  --amber: #9d6125;
  --red: #9f3737;
  --code-bg: #202622;
  --code-fg: #f4f1e8;
  --shadow: 0 18px 55px rgba(63, 47, 26, .09);
  --radius: 8px;
  --max: 1160px;
  --reader: 760px;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
  --serif: "Iowan Old Style", "Songti SC", "Noto Serif SC", Georgia, serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.72;
  text-rendering: optimizeLegibility;
}

a { color: var(--blue); text-decoration-thickness: 1px; text-underline-offset: 3px; }
img { max-width: 100%; height: auto; }
button, input { font: inherit; }

.site-shell { width: min(var(--max), calc(100% - 36px)); margin: 0 auto; }
.reader-shell { width: min(var(--reader), calc(100% - 36px)); margin: 0 auto; }
.wide-shell { width: min(1040px, calc(100% - 36px)); margin: 0 auto; }

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.gate-card {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 30px;
}
.gate-card .eyebrow { margin-top: 0; }
.gate-card h1 {
  margin: 0 0 10px;
  font-size: 28px;
  line-height: 1.16;
  letter-spacing: 0;
}
.gate-card p { color: var(--muted); margin: 0 0 20px; }
.gate-card label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}
.gate-card input {
  width: 100%;
  height: 46px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
}
.gate-card button {
  width: 100%;
  height: 46px;
  margin-top: 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-weight: 820;
  cursor: pointer;
}
.gate-error { min-height: 20px; margin-top: 10px; color: var(--red); font-size: 13px; }
.page.is-gated { display: none; }

.site-top {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 250, .92);
}
.topbar {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 14px;
}
.brand {
  color: var(--ink);
  text-decoration: none;
  font-weight: 860;
}
.top-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.top-actions a { color: var(--muted); text-decoration: none; }
.top-actions a:hover { color: var(--ink); }

.index-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.02fr) minmax(320px, .98fr);
  gap: 34px;
  align-items: center;
  padding: 54px 0 40px;
}
.eyebrow {
  margin: 0 0 12px;
  color: var(--green);
  font-size: 13px;
  font-weight: 860;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.index-hero h1,
.article-hero h1 {
  margin: 0;
  max-width: 860px;
  font-size: 58px;
  line-height: 1.06;
  letter-spacing: 0;
}
.index-hero .lead,
.article-hero .lead {
  max-width: 760px;
  margin: 20px 0 0;
  color: #3d4742;
  font-size: 19px;
  line-height: 1.76;
}
.hero-asset {
  display: block;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.hero-asset img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 26px;
}
.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 14px 16px;
}
.metric small { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 3px; font-size: 24px; line-height: 1.1; }

.index-main { padding: 22px 0 72px; }
.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin: 0 0 16px;
}
.section-head h2 { margin: 0; font-size: 26px; line-height: 1.2; }
.section-head p { margin: 0; max-width: 560px; color: var(--muted); font-size: 15px; }
.post-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.post-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 300px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 20px;
  color: inherit;
  text-decoration: none;
  box-shadow: 0 12px 35px rgba(63, 47, 26, .055);
}
.post-card:hover { border-color: rgba(30, 111, 92, .55); box-shadow: 0 16px 48px rgba(63, 47, 26, .1); }
.post-card.featured { grid-column: span 2; background: #fff9ee; }
.post-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}
.status {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}
.status.public { color: var(--green); border-color: rgba(30, 111, 92, .35); background: #edf7f3; }
.status.internal-preview, .status.internal-prep { color: var(--amber); border-color: rgba(157, 97, 37, .35); background: #fff4e3; }
.post-card h3 {
  margin: 14px 0 12px;
  color: var(--ink);
  font-size: 24px;
  line-height: 1.22;
  letter-spacing: 0;
}
.post-card.featured h3 { font-size: 30px; }
.post-card p { margin: 0; color: #424b46; }
.post-kind { margin-top: 18px; color: var(--green); font-size: 13px; font-weight: 780; }

.article-hero {
  padding: 44px 0 36px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.article-hero .meta-line {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 14px;
}
.article-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 30px;
  align-items: start;
  padding: 34px 0 78px;
}
.article-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 16px 46px rgba(63, 47, 26, .06);
  padding: 38px 44px;
}
.article-card > *:first-child { margin-top: 0; }
.article-card p,
.article-card li {
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.86;
}
.article-card p { margin: 16px 0; }
.article-card h2 {
  margin: 44px 0 14px;
  font-size: 30px;
  line-height: 1.24;
  letter-spacing: 0;
}
.article-card h3 {
  margin: 30px 0 12px;
  font-size: 22px;
  line-height: 1.32;
  letter-spacing: 0;
}
.article-card blockquote {
  margin: 24px 0;
  padding: 18px 20px;
  border-left: 4px solid var(--green);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: #edf7f3;
  color: #263d36;
}
.article-card blockquote p { margin: 0; font-family: var(--sans); font-size: 17px; }
.article-card code {
  padding: .08rem .28rem;
  border: 1px solid #d7d1c4;
  border-radius: 5px;
  background: #f3eee5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .9em;
}
.article-card pre {
  margin: 22px 0;
  padding: 18px;
  overflow-x: auto;
  border-radius: var(--radius);
  background: var(--code-bg);
  color: var(--code-fg);
  line-height: 1.55;
}
.article-card pre code {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 14px;
}
.math-block {
  margin: 22px 0;
  overflow-x: auto;
  padding: 6px 0;
  color: var(--ink);
}
.table-wrap { overflow-x: auto; margin: 24px 0; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; min-width: 680px; background: #fff; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--paper-soft); font-size: 13px; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
figure { margin: 26px 0; }
figure img { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
figcaption { margin-top: 8px; color: var(--muted); font-size: 13px; text-align: center; }

.side-rail {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 12px;
}
.rail-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 16px;
  color: var(--muted);
  font-size: 14px;
}
.rail-card b {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
}
.rail-card a {
  display: block;
  margin: 7px 0;
  color: var(--muted);
  text-decoration: none;
}
.rail-card a:hover { color: var(--blue); text-decoration: underline; }
.source-line {
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}
.article-footer {
  margin-top: 36px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 900px) {
  .index-hero,
  .article-wrap { grid-template-columns: 1fr; }
  .side-rail { position: static; }
  .post-grid { grid-template-columns: 1fr 1fr; }
  .post-card.featured { grid-column: span 2; }
  .metric-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  body { font-size: 16px; }
  .site-shell,
  .wide-shell,
  .reader-shell { width: min(100% - 28px, var(--max)); }
  .topbar { align-items: flex-start; flex-direction: column; padding: 14px 0; }
  .top-actions { justify-content: flex-start; }
  .index-hero h1,
  .article-hero h1 { font-size: 36px; line-height: 1.12; }
  .index-hero { padding-top: 34px; }
  .post-grid { grid-template-columns: 1fr; }
  .post-card,
  .post-card.featured { grid-column: auto; min-height: 0; }
  .post-card.featured h3 { font-size: 25px; }
  .article-card { padding: 25px 21px; }
  .article-card p,
  .article-card li { font-size: 17px; line-height: 1.82; }
  .article-card h2 { font-size: 25px; }
  .metric-row { grid-template-columns: 1fr; }
}
