:root {
  color-scheme: light dark;
  --bg: #fcfcfa;
  --surface: #f4f3ef;
  --surface-code: #f1f0ec;
  --text: #18181b;
  --muted: #52525b;
  --faint: #71717a;
  --border: #e4e3dd;
  --accent: #1d4ed8;
  --accent-hover: #1e3a8a;
  --callout-bg: #f8fafc;
  --callout-border: #cbd5e1;
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-code: #151820;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --faint: #6b7280;
    --border: #262b36;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --callout-bg: #141821;
    --callout-border: #2e3646;
  }
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.68;
  font-feature-settings: "kern" 1, "liga" 1;
}

.container {
  max-width: 780px;
  margin: 0 auto;
  padding: 2.75rem 1.5rem 4.5rem;
}

/* Header & Navigation */
.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  padding-bottom: 1.25rem;
  margin-bottom: 2.25rem;
  border-bottom: 1px solid var(--border);
}

.site-brand {
  font-weight: 650;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}

.site-brand:hover {
  color: var(--accent);
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  font-size: 0.9rem;
}

.site-nav a {
  color: var(--muted);
  text-decoration: none;
}

.site-nav a:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Typography */
h1, h2, h3, h4 {
  color: var(--text);
  line-height: 1.28;
  letter-spacing: -0.015em;
  margin-top: 2.25rem;
  margin-bottom: 0.75rem;
}

h1 {
  font-size: 1.85rem;
  font-weight: 700;
  margin-top: 0;
}

h2 {
  font-size: 1.32rem;
  font-weight: 650;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  margin-top: 2.5rem;
}

h2.no-rule {
  border-top: none;
  padding-top: 0;
  margin-top: 2rem;
}

h3 {
  font-size: 1.08rem;
  font-weight: 620;
  margin-top: 1.75rem;
}

p {
  margin: 0 0 1.1rem;
}

ul, ol {
  margin: 0 0 1.25rem;
  padding-left: 1.4rem;
}

li {
  margin-bottom: 0.42rem;
}

li > ul, li > ol {
  margin-top: 0.35rem;
  margin-bottom: 0.35rem;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

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

/* Hero / Intro */
.subtitle {
  font-size: 1.02rem;
  color: var(--muted);
  margin-top: -0.3rem;
  margin-bottom: 1.1rem;
}

.meta-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 1.6rem;
}

.meta-links span.sep {
  color: var(--faint);
}

/* Cards & Lists on Index */
.note-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0 2rem;
  display: grid;
  gap: 1.1rem;
}

.note-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 1.15rem 1.3rem;
}

.note-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.note-card h3 {
  margin: 0.15rem 0 0.45rem;
  font-size: 1.12rem;
}

.note-card h3 a {
  text-decoration: none;
}

.note-card h3 a:hover {
  text-decoration: underline;
}

.note-card p {
  margin: 0;
  font-size: 0.94rem;
  color: var(--muted);
}

/* Article Header & TOC */
.article-meta {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.65rem;
}

.article-lede {
  font-size: 1.05rem;
  color: var(--muted);
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  margin: 1rem 0 1.75rem;
}

.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.95rem 1.2rem;
  margin: 1.5rem 0 2rem;
  font-size: 0.9rem;
}

.toc-title {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.45rem;
  font-weight: 600;
}

.toc ol {
  margin: 0;
  padding-left: 1.25rem;
}

.toc li {
  margin-bottom: 0.25rem;
}

/* Code & Preformatted Blocks */
code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--surface-code);
  padding: 0.14em 0.36em;
  border-radius: 4px;
  border: 1px solid var(--border);
}

pre {
  background: var(--surface-code);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.95rem 1.1rem;
  overflow-x: auto;
  margin: 1rem 0 1.4rem;
  line-height: 1.5;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.83rem;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  margin: 1.15rem 0 1.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  text-align: left;
}

th, td {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  background: var(--surface);
  font-weight: 620;
  color: var(--text);
  white-space: nowrap;
}

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

/* Callouts */
.callout {
  background: var(--callout-bg);
  border: 1px solid var(--callout-border);
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  padding: 0.9rem 1.1rem;
  margin: 1.25rem 0 1.5rem;
  font-size: 0.93rem;
}

.callout strong {
  display: block;
  margin-bottom: 0.25rem;
}

/* Footer */
.site-footer {
  margin-top: 3.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.84rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

@media (max-width: 600px) {
  .container {
    padding: 1.75rem 1.1rem 3rem;
  }
  h1 {
    font-size: 1.55rem;
  }
  h2 {
    font-size: 1.2rem;
  }
}
