:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-soft: #f6f5f2;
  --card: #ffffff;
  --card-alt: #faf9f7;
  --border: rgba(31, 28, 24, 0.11);
  --border-strong: rgba(31, 28, 24, 0.18);
  --text: #171513;
  --muted: #463f37;
  --soft: #5f5750;
  --accent: #2d2a26;
  --shadow: 0 10px 35px rgba(25, 21, 16, 0.06);
  --grid-opacity: 0.12;
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --serif: 'Source Sans 3', system-ui, sans-serif;
  --sans: 'Source Sans 3', system-ui, sans-serif;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #111111;
  --bg-soft: #171717;
  --card: #171717;
  --card-alt: #1d1d1d;
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f5f2ec;
  --muted: #e0d8cd;
  --soft: #c1b9ad;
  --accent: #f5f2ec;
  --shadow: 0 12px 38px rgba(0, 0, 0, 0.24);
  --grid-opacity: 0.06;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  /* Posts scroll, #home and #posts don't. On classic-scrollbar platforms the
     scrollbar therefore appears and disappears between routes, changing the
     client width and shifting the centred .page-shell by half a scrollbar.
     Reserving the gutter always keeps every route aligned. */
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  color: var(--text);
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.78;
  background: var(--bg);
}

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

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px);
  background-size: 100% 28px;
  opacity: var(--grid-opacity);
}

a {
  color: inherit;
  text-decoration: none;
}

code {
  font-family: var(--mono);
}

.page-shell {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 20px 28px;
}

.site-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 0 14px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-block;
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
}

.site-kicker {
  margin: 8px 0 0;
  color: var(--soft);
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 4px;
}

.site-kicker a {
  color: var(--soft);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.github-icon {
  vertical-align: middle;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.site-nav a,
.back-link,
.link-list a,
.post-body h3 a {
  color: var(--muted);
}

.site-nav a:hover,
.back-link:hover,
.link-list a:hover,
.post-body h3 a:hover {
  color: var(--accent);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--border-strong);
  color: var(--accent);
}

.theme-icon {
  display: block;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-icon-sun {
  display: none;
}

:root[data-theme='dark'] .theme-icon-sun {
  display: block;
}

:root[data-theme='dark'] .theme-icon-moon {
  display: none;
}

.app {
  display: grid;
  gap: 20px;
}

.intro {
  display: grid;
  gap: 12px;
  max-width: 62ch;
  padding-bottom: 4px;
}

.intro-tight {
  max-width: 56ch;
}

.app > .intro:not(.intro-tight) {
  max-width: none;
}

.app > .intro:not(.intro-tight) h1,
.app > .intro:not(.intro-tight) .intro-copy,
.app > .about-card p {
  max-width: none;
}

.eyebrow {
  margin: 0;
  color: var(--soft);
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.intro h1,
.project-head h1,
.section-head h2,
.about-card h2,
.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin: 0;
  font-family: var(--serif);
  letter-spacing: -0.05em;
  line-height: 1.02;
}

.intro h1 {
  font-size: clamp(2rem, 4vw, 2.8rem);
  max-width: 18ch;
}

.intro-copy {
  margin: 0;
  max-width: 58ch;
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1.85;
}

.about-card,
.posts-panel,
.markdown-card,
.error-view {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.about-card {
  padding: 0;
  display: grid;
  gap: 12px;
}

.about-card h2 {
  font-size: 1.3rem;
}

.about-card p {
  margin: 0;
  max-width: 58ch;
  color: var(--text);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(240px, 0.7fr);
  gap: 22px;
  align-items: start;
}

.posts-page {
  display: block;
}

.posts-panel {
  padding: 0;
}

.posts-page .posts-panel {
  width: 100%;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.section-head h2 {
  font-size: 1.45rem;
}

.section-head p {
  margin: 0;
  color: var(--soft);
  font-size: 0.92rem;
}

.posts-list {
  display: grid;
}

.post-row {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

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

.post-meta {
  color: var(--soft);
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: nowrap;
}

.post-body h3 {
  margin: 0 0 7px;
  font-family: var(--serif);
  font-size: clamp(1.15rem, 2.2vw, 1.45rem);
  line-height: 1.15;
}

.post-body p {
  margin: 0;
  color: var(--text);
  line-height: 1.84;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.tag-row span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--soft);
  font-size: 0.74rem;
  font-family: var(--mono);
}

.markdown-body {
  color: var(--text);
  line-height: 1.84;
  max-width: 72ch;
}

.project-content .markdown-body {
  max-width: none;
}

.link-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.project-page {
  display: grid;
  gap: 20px;
}

.project-head {
  display: grid;
  gap: 8px;
  max-width: 68ch;
  padding: 8px 0 4px;
}

.project-head h1 {
  font-size: clamp(2rem, 4vw, 3rem);
}

.markdown-card {
  padding: 0;
}

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

/* Headings share the `margin: 0` rule above with the page chrome, which sits in
   grid containers with their own gap. Prose has no such gap, so re-add spacing
   here or every heading collides with the paragraph under it. */
.markdown-body h1 {
  margin: 2.4rem 0 1rem;
  font-size: 1.85rem;
  line-height: 1.15;
}

.markdown-body h2 {
  margin: 2.2rem 0 0.9rem;
  font-size: 1.5rem;
  line-height: 1.2;
}

.markdown-body h3 {
  margin: 1.8rem 0 0.75rem;
  font-size: 1.2rem;
  line-height: 1.25;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table {
  margin: 0 0 1.15rem;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.2rem;
}

.markdown-body blockquote {
  margin-left: 0;
  padding: 12px 14px;
  border-left: 3px solid var(--accent);
  background: rgba(45, 42, 38, 0.05);
  border-radius: 0 10px 10px 0;
}

.markdown-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* IBM Plex Mono runs wider and heavier than Source Sans 3 at a matched cap
   height, so an optically equal size still reads as bigger than the prose.
   0.85em plus a tighter chip is what actually sits level with body text. */
.markdown-body code {
  padding: 0.1em 0.3em;
  border-radius: 6px;
  background: var(--bg-soft);
  font-family: var(--mono);
  font-size: 0.85em;
}

.markdown-body pre {
  overflow-x: auto;
  padding: 14px;
  border-radius: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
}

.markdown-body th,
.markdown-body td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.loading,
.markdown-error {
  padding: 6px 0;
}

.back-link {
  color: var(--soft);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.error-view {
  padding: 0;
}

.site-footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--soft);
  font-size: 0.92rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.site-footer p {
  margin: 0;
}


.github-icon {
  vertical-align: middle;
}

@media (max-width: 840px) {
  body {
    font-size: 17px;
  }

  .site-header,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .site-header {
    display: grid;
    align-items: start;
  }

  .section-head {
    align-items: start;
    flex-wrap: wrap;
  }

  .post-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

@media (max-width: 600px) {
  .page-shell {
    padding-top: 18px;
    padding-left: 16px;
    padding-right: 16px;
  }

  .site-nav {
    width: 100%;
    justify-content: flex-start;
    gap: 10px;
  }

  .site-nav a {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  .posts-panel,
  .markdown-card,
  .error-view {
    padding: 0;
    border-radius: 18px;
  }

  .brand {
    font-size: 1.6rem;
  }

  .intro h1,
  .project-head h1 {
    max-width: 100%;
  }

  .intro h1 {
    font-size: 2rem;
  }

  .intro-copy {
    font-size: 1rem;
    line-height: 1.75;
  }

  .markdown-body {
    line-height: 1.78;
  }

  .post-meta {
    white-space: normal;
  }

  .theme-toggle {
    width: 36px;
    height: 36px;
  }

  .markdown-body pre {
    padding: 12px;
    font-size: 0.9rem;
  }

  .markdown-body table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}