:root {
  --bg: #f6f3ec;
  --surface: #fbf9f3;
  --text: #1a1916;
  --text-2: #4a4844;
  --muted: #8a8780;
  --accent: #b5432d;
  --rule: #e2ddd1;
  --rule-soft: #ece7da;
  --link-underline: #c9c3b3;
  --footnote-bg: rgba(26, 25, 22, 0.08);
  --footnote-bg-hover: rgba(26, 25, 22, 0.16);
  --footnote-tooltip-bg: #fbf9f3;
  --max: 680px;
}

html.dark {
  --bg: #181714;
  --surface: #221f1a;
  --text: #ece8dc;
  --text-2: #b6b1a1;
  --muted: #8a857a;
  --accent: #e07a5f;
  --rule: #34302a;
  --rule-soft: #28251f;
  --link-underline: #4a4640;
  --footnote-bg: rgba(236, 232, 220, 0.12);
  --footnote-bg-hover: rgba(236, 232, 220, 0.24);
  --footnote-tooltip-bg: #221f1a;
}

* {
  box-sizing: border-box;
}

::selection {
  background: rgba(181, 67, 45, 0.18);
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
  border-radius: 2px;
}

/* Reading progress bar */
.read-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: var(--accent);
  z-index: 1000;
  transition: width 0.05s linear;
  pointer-events: none;
}

/* Latest pill on index */
.latest-pill {
  display: inline-block;
  margin-left: 10px;
  padding: 2px 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: var(--accent);
  color: #fff;
  border-radius: 99px;
  vertical-align: middle;
}

/* Prev/next post navigation */
.post-nav {
  display: flex;
  gap: 16px;
  margin: 56px 0 0;
  padding-top: 28px;
  border-top: 1px solid var(--rule);
}

.post-nav a {
  flex: 1;
  text-decoration: none;
  color: var(--text);
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.post-nav a:hover {
  border-color: var(--text-2);
}

.post-nav .nav-label {
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.post-nav .nav-title {
  font-weight: 700;
  font-size: 1rem;
}

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

@media (max-width: 520px) {
  .post-nav { flex-direction: column; }
  .post-nav .next { text-align: left; }
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Source Serif 4", "Source Serif Pro", "Iowan Old Style", Charter, Georgia, "Times New Roman", Times, serif;
  font-size: 19px;
  line-height: 1.65;
  font-weight: 400;
  font-feature-settings: "kern" 1, "liga" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.wrap {
  max-width: var(--max);
  margin: 0 auto;
  padding: 72px 24px 96px;
}

/* Header */
.site-header {
  margin-bottom: 56px;
}

.name {
  font-size: 2.4rem;
  font-weight: 500;
  letter-spacing: -0.015em;
  margin: 0 0 8px;
  line-height: 1.1;
}

.tagline {
  color: var(--muted);
  font-style: italic;
  margin: 0 0 20px;
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.85rem;
}

.links a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.links a:hover {
  color: var(--text);
  border-color: var(--text);
}

/* Sections */
.section {
  margin-bottom: 56px;
}

.section p a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  border-bottom: 0;
}

.section p a:hover {
  text-decoration-color: var(--text);
}

.section-title {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  padding-bottom: 10px;
  margin: 0 0 24px;
  border-bottom: 1px solid var(--rule);
}

/* Post list */
.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-item {
  margin-bottom: 32px;
}

.post-link {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  text-decoration: none;
  color: var(--text);
}

.post-title {
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  transition: color 0.15s ease;
}

.post-link:hover .post-title {
  color: var(--text-2);
}

.post-date {
  flex-shrink: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.post-excerpt {
  color: var(--muted);
  margin: 6px 0 0;
  font-size: 1rem;
  line-height: 1.55;
}

/* Article */
.article-header {
  margin-bottom: 40px;
}

.article-title {
  font-size: clamp(2.2rem, 5vw, 3.2rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.08;
  margin: 0 0 14px;
  text-wrap: balance;
}

.article-meta {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.85rem;
  color: var(--muted);
}

.article-body p {
  margin: 0 0 22px;
}

.article-body h2 {
  font-size: 1.5rem;
  font-weight: 500;
  margin: 48px 0 16px;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.article-body em {
  font-style: italic;
}

.article-body blockquote {
  margin: 40px 0;
  padding: 0 24px;
  text-align: center;
  border: 0;
  color: var(--text);
  font-style: italic;
  font-size: 1.5rem;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

.section-break {
  border: 0;
  height: auto;
  margin: 44px 0;
  position: relative;
}

.section-break::after {
  content: "\2042";
  display: block;
  text-align: center;
  font-family: inherit;
  font-weight: 300;
  font-size: 1.6rem;
  color: var(--text-2);
}

.unfinished {
  color: var(--muted);
  font-style: italic;
}

/* Lead paragraph: first paragraph of the body */
.article-body .lead {
  font-size: 1.18rem;
  line-height: 1.6;
  color: var(--text);
}

/* Drop cap on the lead paragraph */
.article-body .lead::first-letter {
  float: left;
  font-family: inherit;
  font-weight: 400;
  font-size: 4.6rem;
  line-height: 0.86;
  padding: 6px 14px 0 0;
  margin-top: 4px;
  color: var(--accent);
}

/* Marginalia: floats to the right of the body on wide screens */
.article-body .margin-note {
  float: right;
  clear: right;
  width: 200px;
  margin: 4px -224px 16px 24px;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.5;
  font-style: italic;
  color: var(--text-2);
  border-top: 1px solid var(--rule);
  padding-top: 10px;
}

.article-body .margin-note .margin-label {
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-style: normal;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  margin-bottom: 6px;
}

@media (max-width: 1024px) {
  .article-body .margin-note {
    float: none;
    width: auto;
    margin: 18px 0 24px;
    padding: 12px 16px;
    border-top: 0;
    border-left: 2px solid var(--rule);
    background: var(--rule-soft);
  }
  .article-body .lead::first-letter {
    font-size: 3.6rem;
  }
}

/* Article-page widening so margin notes have a gutter */
body.article .wrap {
  max-width: 944px;
  padding-right: 264px;
}

@media (max-width: 1024px) {
  body.article .wrap {
    max-width: var(--max);
    padding-right: 24px;
  }
}

/* Footnotes (hover tooltip) */
.article-body sup.fn {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.68rem;
  font-weight: 600;
  background: var(--footnote-bg);
  border-radius: 4px;
  margin: 0 2px;
  padding: 2px 4px 1px;
  position: relative;
  cursor: help;
  vertical-align: super;
  line-height: 1;
  transition: background 0.15s ease;
}

.article-body sup.fn a {
  color: var(--text);
  text-decoration: none;
  border: 0;
}

.article-body sup.fn:hover {
  background: var(--footnote-bg-hover);
}

.fn-tip {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: min(320px, 80vw);
  background: var(--footnote-tooltip-bg);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 12px 14px;
  font-family: var(--serif, inherit);
  font-size: 0.92rem;
  font-style: normal;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: normal;
  text-transform: none;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  transition: opacity 0.15s ease;
  pointer-events: none;
}

@media (min-width: 768px) {
  .article-body sup.fn:hover .fn-tip,
  .article-body sup.fn:focus-within .fn-tip {
    visibility: visible;
    opacity: 1;
  }
}

/* Bottom footnote list */
.footnotes {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--rule-soft);
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--text-2);
}

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

.footnotes li {
  margin: 0 0 14px;
  padding-left: 28px;
  position: relative;
}

.footnotes li sup {
  position: absolute;
  left: 0;
  top: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-weight: 600;
  font-size: 0.75rem;
}

/* Dark mode toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  width: 40px;
  height: 22px;
  padding: 0;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s ease, background 0.15s ease;
  margin-left: auto;
}

.theme-toggle::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-2);
  top: 3px;
  left: 3px;
  transition: transform 0.2s ease, background 0.2s ease;
}

html.dark .theme-toggle::before {
  transform: translateX(18px);
  background: var(--text);
}

.theme-toggle:hover {
  border-color: var(--text-2);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.site-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.site-header .header-text {
  flex: 1;
  min-width: 0;
}

.article-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 32px;
}

.article-topbar .back-link {
  margin-bottom: 0;
}

/* Mentor / source credit card */
.mentor-card {
  margin: 28px 0 40px;
  padding: 18px 22px;
  border-left: 2px solid var(--rule);
  background: var(--rule-soft);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text);
}

.mentor-card .mentor-label {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.68rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.mentor-card a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-underline-offset: 2px;
}

.mentor-card a:hover {
  text-decoration-color: var(--text);
}

/* Book figure */
.book-figure {
  margin: 40px auto;
  text-align: center;
  max-width: 360px;
}

.book-figure img {
  width: 100%;
  height: auto;
  display: block;
}

.book-figure figcaption {
  margin-top: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

.book-figure figcaption a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-underline-offset: 2px;
}

/* Pull-quote with attribution */
.article-body blockquote cite {
  display: block;
  margin-top: 10px;
  font-style: normal;
  font-size: 0.9rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

/* Inline highlight for key takeaway lines */
.article-body .highlight {
  background: linear-gradient(180deg, transparent 60%, rgba(181, 67, 45, 0.22) 60%);
  padding: 0 2px;
}

/* Numbered list (takeaways) */
.article-body ol.takeaways {
  margin: 24px 0;
  padding-left: 0;
  list-style: none;
  counter-reset: takeaway;
}

.article-body ol.takeaways li {
  counter-increment: takeaway;
  margin: 0 0 22px;
  padding-left: 56px;
  position: relative;
}

.article-body ol.takeaways li::before {
  content: counter(takeaway, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 2px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.article-body a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  border-bottom: 0;
}

.article-body a:hover {
  text-decoration-color: var(--text);
}

.article-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--rule-soft);
  padding: 2px 6px;
  border-radius: 4px;
}

.back-link {
  display: inline-block;
  margin-bottom: 40px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
}

.back-link:hover {
  color: var(--text);
}

/* Footer */
.site-footer {
  margin-top: 72px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.8rem;
  color: var(--muted);
}

@media (max-width: 520px) {
  body { font-size: 18px; }
  .wrap { padding: 48px 20px 72px; }
  .name { font-size: 2rem; }
  .post-link { flex-direction: column; gap: 2px; }
}
