/* ---------- Tokens ---------- */
:root {
  --bg: #fdf6e3;
  --text: #073642;
  --muted: #4f6168;
  --faint: #e6dfca;
  --accent: #1a6397;
  --notice-bg: #eee8d5;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --measure: 38rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #002b36;
    --text: #e4e2d6;
    --muted: #9fb0b2;
    --faint: #0f3d49;
    --accent: #6fb6e8;
    --notice-bg: #073642;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #002b36;
  --text: #e4e2d6;
  --muted: #9fb0b2;
  --faint: #0f3d49;
  --accent: #6fb6e8;
  --notice-bg: #073642;
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.1875rem;
  line-height: 1.7;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

@media (max-width: 40rem) {
  body { font-size: 1.0625rem; line-height: 1.65; }
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}
a:hover { text-decoration-thickness: 2px; }
a:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

img { max-width: 100%; height: auto; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0.5rem;
  background: var(--bg);
  padding: 0.25rem 0.5rem;
  font-family: var(--sans);
  font-size: 0.875rem;
}
.skip-link:focus { left: 1rem; }

/* ---------- Layout ---------- */
main {
  max-width: calc(var(--measure) + 2.5rem);
  margin: 0 auto;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}

.site-header {
  position: absolute;
  top: 1rem;
  right: 1rem;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--text); }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

main {
  padding-top: 5rem;
  padding-bottom: 4rem;
}

main { flex: 1 0 auto; width: 100%; }

.site-footer {
  width: 100%;
  max-width: calc(var(--measure) + 2.5rem);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  font-family: var(--sans);
  font-size: 0.8125rem;
  color: var(--muted);
}
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--text); }
.site-footer span { margin: 0 0.5rem; }

/* ---------- Typography ---------- */
h1, h2, h3, h4 {
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.005em;
}

h1 {
  font-size: 2.5rem;
  margin: 0 0 0.75rem;
  letter-spacing: -0.015em;
}
@media (max-width: 40rem) { h1 { font-size: 2rem; } }

.prose h2 { font-size: 1.5rem; margin: 3rem 0 1rem; }
.prose h3 { font-size: 1.2rem; margin: 2.25rem 0 0.75rem; font-style: italic; }
.prose h2, .prose h3 { scroll-margin-top: 1.5rem; }

.prose p, .prose ul, .prose ol, .prose blockquote { margin: 0 0 1.4em; }
.prose li { margin-bottom: 0.35em; }
.prose blockquote {
  margin-left: 0;
  padding-left: 1.25rem;
  border-left: 2px solid var(--faint);
  color: var(--muted);
  font-style: italic;
}
.prose hr { border: 0; border-top: 1px solid var(--faint); margin: 3rem auto; width: 30%; }

code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85em; }
pre { overflow-x: auto; padding: 1rem; background: var(--notice-bg); border-radius: 4px; line-height: 1.5; }

.subtitle {
  margin: 0 0 1rem;
  font-size: 1.25rem;
  font-style: italic;
  color: var(--muted);
  line-height: 1.45;
}

.meta {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.page-header, .essay-header { margin-bottom: 2.5rem; }

/* ---------- Essay ---------- */
.notice {
  margin: 0 0 2.5rem;
  padding: 0.75rem 1rem;
  background: var(--notice-bg);
  border-left: 3px solid var(--accent);
  font-family: var(--sans);
  font-size: 0.875rem;
  line-height: 1.5;
}

.toc {
  margin: 0 0 3rem;
  padding: 1.25rem 0;
  border-top: 1px solid var(--faint);
  border-bottom: 1px solid var(--faint);
  font-family: var(--sans);
  font-size: 0.875rem;
}
.toc-title {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.toc ol { margin: 0; padding-left: 1.25rem; color: var(--muted); }
.toc li { margin: 0.2rem 0; }
.toc a { color: var(--text); text-decoration: none; }
.toc a:hover { color: var(--accent); text-decoration: underline; }

/* kramdown footnotes */
sup[role="doc-noteref"], .footnote-ref { line-height: 0; }
a.footnote {
  text-decoration: none;
  font-family: var(--sans);
  font-size: 0.75em;
  padding: 0 0.1em;
}

.footnotes {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--faint);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--muted);
}
.footnotes::before {
  content: "Notes";
  display: block;
  margin-bottom: 0.75rem;
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.footnotes ol { padding-left: 1.5rem; margin: 0; }
.footnotes li { margin-bottom: 0.6rem; }
.footnotes p { margin: 0; }
.reversefootnote { text-decoration: none; margin-left: 0.25rem; }
.footnotes li:target, sup:target { background: var(--notice-bg); border-radius: 3px; }
.footnotes li, sup { scroll-margin-top: 1.5rem; }

/* ---------- Home ---------- */
.home h1 { font-size: clamp(2.75rem, 9vw, 4rem); margin-bottom: 1.5rem; }
.lede { font-size: 1.3rem; line-height: 1.6; }
@media (max-width: 40rem) { .lede { font-size: 1.15rem; } }

.section-title {
  margin: 3.5rem 0 1rem;
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.essay-list { list-style: none; margin: 0; padding: 0; }
.essay-list li { padding: 1.25rem 0; border-bottom: 1px solid var(--faint); }
.essay-list li:first-child { padding-top: 0; }
.essay-list a { color: var(--text); text-decoration: none; font-size: 1.25rem; line-height: 1.35; }
.essay-list a:hover { color: var(--accent); }
.essay-list p { margin: 0.3rem 0 0; color: var(--muted); font-size: 1rem; line-height: 1.55; }
.essay-list .meta { margin-top: 0.4rem; font-size: 0.8125rem; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
html { scroll-behavior: smooth; }
