/* ── Fonts ─────────────────────────────────────────────────────────── */
@font-face {
  font-family: 'Newsreader';
  src: url('/assets/fonts/Newsreader-Variable.woff2') format('woff2');
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Newsreader';
  src: url('/assets/fonts/Newsreader-Variable-Italic.woff2') format('woff2');
  font-weight: 200 800;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: 'Assistant';
  src: url('/assets/fonts/Assistant-Variable.woff2') format('woff2');
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

/* ── Reset ─────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Theme Tokens ──────────────────────────────────────────────────── */
:root,
[data-theme="light"] {
  --bg:           #f7f6f3;
  --bg-subtle:    #efede8;
  --text:         #161616;
  --text-muted:   #5a5a58;
  --accent:       #0f5a3a;
  --link:         #0f5a3a;
  --link-hover:   #0a3d27;
  --border:       #d8d4cc;
  --code-bg:      #efede8;
  --code-text:    #161616;
  --pre-bg:       #1e1e1e;
  --pre-text:     #d4d4d4;
  --blockquote-bg: #f0ede7;
  --blockquote-border: #c5c0b8;
  --focus-ring:   #0f5a3a;
  --tag-bg:       #e6e3dc;
  --tag-text:     #4a4a48;
}

[data-theme="dark"] {
  --bg:           #111110;
  --bg-subtle:    #1c1c1a;
  --text:         #e2e0dc;
  --text-muted:   #9a9893;
  --accent:       #6ecf96;
  --link:         #6ecf96;
  --link-hover:   #a3e4bc;
  --border:       #2e2d2a;
  --code-bg:      #1c1c1a;
  --code-text:    #e2e0dc;
  --pre-bg:       #0c0c0b;
  --pre-text:     #d4d4d4;
  --blockquote-bg: #1a1918;
  --blockquote-border: #3d3b37;
  --focus-ring:   #6ecf96;
  --tag-bg:       #282724;
  --tag-text:     #b0ada8;
}

/* ── Base ──────────────────────────────────────────────────────────── */
html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: auto;
}

body {
  font-family: 'Assistant', ui-sans-serif, -apple-system, "Segoe UI", sans-serif;
  font-size: 1.0625rem;     /* ~17px – comfortable for reading */
  line-height: 1.7;
  color: var(--text);
  background-color: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Focus ─────────────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ── Skip Link ─────────────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
  z-index: 100;
  padding: 0.75rem 1.5rem;
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
  text-decoration: none;
  border: 2px solid var(--focus-ring);
  border-radius: 0.375rem;
}
.skip-link:focus {
  position: fixed;
  top: 1rem;
  left: 1rem;
  width: auto;
  height: auto;
}

/* ── Transitions (color/opacity only, motion-safe) ─────────────────── */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
  body,
  a,
  .theme-toggle {
    transition: color 0.2s ease, background-color 0.2s ease, opacity 0.2s ease;
  }
}

/* ── Layout ────────────────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 42rem;
  margin-inline: auto;
  padding-inline: 1.5rem;
}

main {
  flex: 1;
  padding-block: 2rem;
}

/* ── Header ────────────────────────────────────────────────────────── */
.site-header {
  padding-block: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.site-nav a {
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: none;
  color: var(--text-muted);
  padding: 0.5rem 0.75rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--text);
}

/* ── Theme Toggle ──────────────────────────────────────────────────── */
.theme-toggle {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text);
  cursor: pointer;
  padding: 0.5rem;
  min-width: 44px;
  min-height: 44px;
  border-radius: 0.375rem;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* ── Footer ────────────────────────────────────────────────────────── */
.site-footer {
  padding-block: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--text-muted);
}

.site-footer .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.footer-links {
  display: flex;
  gap: 1rem;
  list-style: none;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
}

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

/* ── Links ─────────────────────────────────────────────────────────── */
a {
  color: var(--link);
}

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

/* ── Headings ──────────────────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: 'Newsreader', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  line-height: 1.3;
  font-weight: 700;
  color: var(--text);
}

h1 { font-size: 2.5rem;   margin-block: 0 1rem; }
h2 { font-size: 1.875rem; margin-block: 2.5rem 0.75rem; }
h3 { font-size: 1.375rem; margin-block: 2rem 0.5rem; }

/* ── Prose (article content) ───────────────────────────────────────── */
.prose {
  font-family: 'Newsreader', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
}

.prose p {
  margin-block: 1.25rem;
}

.prose p:first-child {
  margin-block-start: 0;
}

.prose ul,
.prose ol {
  margin-block: 1.25rem;
  padding-inline-start: 1.75rem;
}

.prose li {
  margin-block: 0.35rem;
}

.prose li > ul,
.prose li > ol {
  margin-block: 0.25rem;
}

/* ── Blockquote ────────────────────────────────────────────────────── */
.prose blockquote {
  margin-block: 1.5rem;
  padding: 1rem 1.25rem;
  border-left: 3px solid var(--blockquote-border);
  background: var(--blockquote-bg);
  border-radius: 0 0.375rem 0.375rem 0;
  color: var(--text-muted);
}

.prose blockquote p {
  margin-block: 0.5rem;
}

.prose blockquote p:first-child {
  margin-block-start: 0;
}

.prose blockquote p:last-child {
  margin-block-end: 0;
}

/* ── Code ──────────────────────────────────────────────────────────── */
code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.875em;
}

:not(pre) > code {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.15em 0.35em;
  border-radius: 0.25rem;
}

pre {
  margin-block: 1.5rem;
  padding: 1.25rem;
  background: var(--pre-bg);
  color: var(--pre-text);
  border-radius: 0.5rem;
  overflow-x: auto;
  line-height: 1.55;
  font-size: 0.875rem;
}

pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* ── Horizontal Rule ───────────────────────────────────────────────── */
.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin-block: 2.5rem;
}

/* ── Tables ────────────────────────────────────────────────────────── */
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin-block: 1.5rem;
  font-size: 0.9375rem;
}

.prose th,
.prose td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  text-align: left;
}

.prose th {
  background: var(--bg-subtle);
  font-weight: 600;
}

/* ── Images ────────────────────────────────────────────────────────── */
.prose img {
  max-width: 100%;
  height: auto;
  border-radius: 0.375rem;
}

.prose figure {
  margin-block: 1.5rem;
}

.prose figure img {
  display: block;
}

.prose figcaption {
  margin-block-start: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Post Meta ─────────────────────────────────────────────────────── */
.post-meta {
  color: var(--text-muted);
  font-size: 0.9375rem;
  margin-block: 0.5rem 2rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}

.post-meta time {
  white-space: nowrap;
}

.reading-time {
  white-space: nowrap;
}

/* ── Tags ──────────────────────────────────────────────────────────── */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  list-style: none;
  padding: 0;
  margin-block: 0.75rem;
}

.tag {
  font-size: 0.8125rem;
  background: var(--tag-bg);
  color: var(--tag-text);
  padding: 0.15rem 0.55rem;
  border-radius: 0.25rem;
}

/* ── Related Reading ───────────────────────────────────────────────── */
.related-reading {
  margin-block-start: 3rem;
  padding-block-start: 2rem;
  border-top: 1px solid var(--border);
}

.related-reading h2 {
  font-size: 1.125rem;
  margin-block: 0 0.75rem;
}

.related-reading ul {
  list-style: none;
  padding: 0;
}

.related-reading li {
  margin-block: 0.375rem;
}

.related-reading a {
  text-decoration: none;
}

.related-reading a:hover {
  text-decoration: underline;
}

/* ── Post List (Writing page) ──────────────────────────────────────── */
.post-list {
  list-style: none;
  padding: 0;
}

.post-list-item {
  padding-block: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.post-list-item:first-child {
  padding-block-start: 0;
}

.post-list-item:last-child {
  border-bottom: none;
}

.post-list-item h2 {
  font-size: 1.25rem;
  margin-block: 0 0.25rem;
}

.post-list-item h2 a {
  text-decoration: none;
  color: var(--text);
}

.post-list-item h2 a:hover {
  color: var(--link);
}

.post-list-item .post-meta {
  margin-block: 0.25rem 0.5rem;
}

.post-list-item .description {
  color: var(--text-muted);
  font-size: 0.9375rem;
  margin: 0;
}

/* ── Page Title ────────────────────────────────────────────────────── */
.page-title {
  margin-block-end: 1.5rem;
}

/* ── Home ──────────────────────────────────────────────────────────── */
.home-intro {
  font-family: 'Newsreader', Georgia, serif;
  font-size: 1.25rem;
  line-height: 1.75;
  margin-block-end: 3rem;
}

.home-intro p {
  margin-block: 1rem;
}

.home-intro p:first-child {
  margin-block-start: 0;
}

.section-heading {
  font-family: 'Newsreader', Georgia, serif;
  font-size: 1.25rem;
  font-weight: 600;
  margin-block: 3rem 1rem;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text-muted);
}

/* ── 404 ───────────────────────────────────────────────────────────── */
.error-page {
  text-align: center;
  padding-block: 4rem;
}

.error-page h1 {
  font-size: 4rem;
  margin-block-end: 0.5rem;
}

.error-page p {
  color: var(--text-muted);
  margin-block: 1rem;
}

/* ── Selection ─────────────────────────────────────────────────────── */
::selection {
  background: var(--accent);
  color: #fff;
}
[data-theme="dark"] ::selection {
  background: var(--accent);
  color: #111;
}

/* ── Prose Links ───────────────────────────────────────────────────── */
.prose a {
  text-decoration: underline;
  text-underline-offset: 0.15em;
  text-decoration-thickness: 1px;
}

.prose a:hover {
  text-decoration-thickness: 2px;
}

/* ── Print ─────────────────────────────────────────────────────────── */
@media print {
  .site-header,
  .site-footer,
  .theme-toggle,
  .tags {
    display: none !important;
  }

  body {
    font-size: 12pt;
    line-height: 1.5;
    color: #000;
    background: #fff;
  }

  a {
    color: #000;
    text-decoration: underline;
  }

  pre {
    border: 1px solid #ccc;
    background: #f9f9f9;
    color: #000;
  }

  .container {
    max-width: 100%;
    padding: 0;
  }
}
