@font-face {
  font-family: "Source Serif 4";
  src: url("../fonts/source-serif-4-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Source Sans 3";
  src: url("../fonts/source-sans-3-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;

  --bg: #e9ecf1;
  --bg-deep: #dde2ea;
  --bg-glow: #d5dbe6;
  --bg-bottom: #e6e9f0;
  --surface: #f3f5f8;
  --text: #1a1d22;
  --muted: #4a515c;
  --border: #c5cbd6;
  --link: #1c4d89;
  --link-underline: #1c4d8940;
  --code-bg: #e2e6ed;
  --focus: #1c4d89;

  --measure: 65ch;
  --font-body: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia,
    "Times New Roman", serif;
  --font-ui: "Source Sans 3", "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  --lh-body: 1.65;
  --lh-heading: 1.2;
  --lh-meta: 1.4;
}

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

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1.125rem;
  line-height: var(--lh-body);
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 110% 70% at 50% -15%, var(--bg-glow) 0%, transparent 58%),
    linear-gradient(180deg, var(--bg-deep) 0%, var(--bg) 32%, var(--bg-bottom) 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

a {
  color: var(--link);
  text-underline-offset: 0.12em;
  transition: text-decoration-thickness 120ms ease, color 120ms ease;
}

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

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  a {
    transition: none;
  }

  body {
    background-attachment: scroll;
  }
}

.skip-link {
  position: absolute;
  inset-inline-start: 0.75rem;
  inset-block-start: 0.75rem;
  padding: 0.4rem 0.75rem;
  background: var(--surface);
  color: var(--link);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  z-index: 1;
  clip-path: inset(50%);
  width: 1px;
  height: 1px;
  overflow: hidden;
  white-space: nowrap;
}

.skip-link:focus {
  clip-path: none;
  width: auto;
  height: auto;
  overflow: visible;
}

.skip-link:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.site-header,
main,
.site-footer {
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: 1.25rem;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3) var(--space-5);
  padding-block: var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.home .site-header {
  padding-block: var(--space-6) var(--space-3);
  border-bottom-color: transparent;
}

.site-title {
  font-family: var(--font-ui);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: var(--lh-heading);
  color: var(--text);
  text-decoration: none;
}

.home .site-title {
  font-size: clamp(1.85rem, 4.5vw, 2.35rem);
  font-weight: 800;
  letter-spacing: -0.035em;
}

.site-title:hover {
  color: var(--text);
  text-decoration: none;
}

.site-nav {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  line-height: var(--lh-meta);
}

.site-nav a {
  display: inline-block;
  color: var(--muted);
  text-decoration: none;
  padding: 0.45rem 0.4rem;
  margin-inline-end: 0.5rem;
  margin-block: -0.45rem;
}

.site-nav a:last-child {
  margin-inline-end: 0;
}

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

.theme-toggle {
  display: inline-block;
  margin: 0;
  margin-block: -0.45rem;
  padding: 0.45rem 0.4rem;
  border: 0;
  background: transparent;
  font-family: var(--font-ui);
  font-size: inherit;
  line-height: var(--lh-meta);
  color: var(--muted);
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--text);
  text-decoration: underline;
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle {
    transition: none;
  }
}

main {
  padding-block: var(--space-5) var(--space-7);
}

.home main {
  padding-block-start: var(--space-2);
}

.site-intro {
  margin: 0 0 var(--space-6);
  font-family: var(--font-body);
  font-size: 1.2rem;
  line-height: var(--lh-body);
  color: var(--muted);
  max-width: 28ch;
}

.section-label {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: var(--lh-meta);
  color: var(--muted);
  margin: 0 0 var(--space-4);
}

.site-footer {
  padding-block: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  line-height: var(--lh-meta);
  color: var(--muted);
}

.site-footer a {
  color: inherit;
}

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

.not-found .section-label {
  margin-bottom: var(--space-2);
}

.not-found h1 {
  margin-bottom: var(--space-3);
}

.not-found-links {
  margin-top: var(--space-5);
  font-family: var(--font-ui);
  font-size: 0.95rem;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-ui);
  line-height: var(--lh-heading);
  letter-spacing: -0.02em;
  color: var(--text);
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 var(--space-4);
}

h2 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-block: var(--space-5) var(--space-2);
}

h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-block: var(--space-4) var(--space-2);
}

h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-block: var(--space-4) var(--space-2);
}

.post-list,
.tag-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-item {
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--border);
}

.post-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
  margin-bottom: 0;
}

.post-item h2 {
  margin: 0 0 var(--space-1);
  font-size: 1.25rem;
}

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

.post-item a:hover,
.post-item a:focus-visible {
  color: var(--link);
  text-decoration: underline;
}

.post-desc {
  margin: var(--space-1) 0 0;
  color: var(--muted);
  font-size: 1.05rem;
}

time,
.reading-time,
.post-meta {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  line-height: var(--lh-meta);
  color: var(--muted);
}

.post-item time {
  display: block;
  margin-bottom: var(--space-1);
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  margin: 0 0 var(--space-2);
}

.post-meta time {
  display: inline;
  margin: 0;
}

.tags {
  margin: var(--space-3) 0 0;
  font-family: var(--font-ui);
  font-size: 0.875rem;
  line-height: var(--lh-meta);
}

.tag {
  display: inline-block;
  padding: 0.4rem 0.2rem;
  margin-block: -0.2rem;
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
}

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

.tag:not(:last-child)::after {
  content: " ·";
  color: var(--muted);
  text-decoration: none;
  margin-inline-end: 0.35rem;
}

.tag-list li {
  margin-bottom: var(--space-2);
  font-family: var(--font-ui);
}

.tag-list .count {
  color: var(--muted);
}

.post-header {
  margin-bottom: var(--space-5);
}

.post-header h1 {
  margin-bottom: var(--space-2);
}

.post-body > *:first-child {
  margin-top: 0;
}

.post-body p,
.post-body ul,
.post-body ol,
.post-body pre,
.post-body blockquote,
.post-body figure,
.post-body table {
  margin-block: 0 var(--space-4);
}

.post-body h2,
.post-body h3,
.post-body h4 {
  margin-block: var(--space-5) var(--space-3);
}

.post-body a {
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
}

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

.post-body ul,
.post-body ol {
  padding-inline-start: 1.35em;
}

.post-body li + li {
  margin-top: var(--space-1);
}

.post-body li ul,
.post-body li ol {
  margin-block: var(--space-1) 0;
}

.post-body hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin-block: var(--space-6);
}

.post-body img {
  max-width: 100%;
  height: auto;
  display: block;
}

.post-body pre {
  overflow-x: auto;
  padding: 0.85rem 1rem;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9rem;
  line-height: 1.45;
}

.post-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.post-body :not(pre) > code {
  padding: 0.1em 0.35em;
  background: var(--code-bg);
  border-radius: 3px;
}

.post-body blockquote {
  margin-inline: 0;
  padding-inline: var(--space-4);
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.post-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
  font-family: var(--font-ui);
  font-size: 0.95rem;
}

.post-nav a {
  max-width: 45%;
  text-decoration: none;
  color: var(--text);
}

.post-nav a:hover {
  color: var(--link);
  text-decoration: underline;
}

.post-nav-label {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--space-1);
}

.post-nav-older {
  margin-inline-start: auto;
  text-align: end;
}

/* System dark unless data-theme="light". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12151a;
    --bg-deep: #0c0e12;
    --bg-glow: #1a2230;
    --bg-bottom: #0f1218;
    --surface: #1c2129;
    --text: #e6e9ef;
    --muted: #9aa3b0;
    --border: #2e3540;
    --link: #7eb0e8;
    --link-underline: #7eb0e866;
    --code-bg: #1a1f28;
    --focus: #7eb0e8;
  }
}

/* Toggle override (wins over system). */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12151a;
  --bg-deep: #0c0e12;
  --bg-glow: #1a2230;
  --bg-bottom: #0f1218;
  --surface: #1c2129;
  --text: #e6e9ef;
  --muted: #9aa3b0;
  --border: #2e3540;
  --link: #7eb0e8;
  --link-underline: #7eb0e866;
  --code-bg: #1a1f28;
  --focus: #7eb0e8;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #e9ecf1;
  --bg-deep: #dde2ea;
  --bg-glow: #d5dbe6;
  --bg-bottom: #e6e9f0;
  --surface: #f3f5f8;
  --text: #1a1d22;
  --muted: #4a515c;
  --border: #c5cbd6;
  --link: #1c4d89;
  --link-underline: #1c4d8940;
  --code-bg: #e2e6ed;
  --focus: #1c4d89;
}
