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

/* ---- Tokens ---- */
:root {
  --prose-max: 38rem;
  --fg: #1a1a1a;
  --fg-muted: #5b5b5b;
  --bg: #fafafa;
  --bg-code: #f0eee9;
  --rule: #d8d4cc;
  --thread-rail: #a89f91;
  --link: #1b4f9e;
  --link-hover: #0a2a5b;
  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 2.5rem;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---- Typography ---- */
html {
  font-family: var(--font-sans);
  color: var(--fg);
  background: var(--bg);
  font-size: 17px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4, h5, h6 {
  line-height: 1.25;
  margin: var(--space-3) 0 var(--space-2);
}
h1 { font-size: 1.8rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }

p, ul, ol, blockquote, pre { margin: 0 0 var(--space-2); }

a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--link-hover); }

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-code);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
pre {
  font-family: var(--font-mono);
  background: var(--bg-code);
  padding: var(--space-2);
  border-radius: 4px;
  overflow-x: auto;
}
pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 0.9rem;
}

blockquote {
  margin-inline: 0;
  padding-inline: var(--space-2);
  border-left: 3px solid var(--rule);
  color: var(--fg-muted);
}

hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: var(--space-3) 0;
}

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

/* ---- Layout ---- */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
header, main, footer {
  width: 100%;
  max-width: var(--prose-max);
  margin-inline: auto;
  padding-inline: var(--space-2);
}
header {
  padding-top: var(--space-3);
  padding-bottom: var(--space-2);
}
header a {
  font-weight: 600;
  text-decoration: none;
  color: var(--fg);
}
/* flex:1 inside the min-height:100vh flex-column body keeps the footer anchored
   to the viewport bottom on short pages (sticky footer), so the prev/next +
   site-nav cluster stays tight at the bottom. */
main { flex: 1; padding-bottom: var(--space-4); }
footer {
  padding-top: var(--space-3);
  padding-bottom: var(--space-3);
  color: var(--fg-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--rule);
}

/* ---- Entry list ---- */
.entry-list {
  list-style: none;
  padding: 0;
}
.entry-list li {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.entry-list li:last-child { border-bottom: none; }
.entry-date {
  color: var(--fg-muted);
  font-size: 0.85rem;
}

/* ---- Thread rail ---- */
/* Consecutive entries of one continuity thread share a left rule, so the list
   shows the thread without tags or "part N" labels. Position classes
   (start/mid/end) are emitted by threads.annotate_threads for future tuning. */
/* The rail is a pseudo-element in the left gutter, NOT a content-box border:
   a border-left would push the title text right and break alignment with
   non-thread rows. The bar floats into main's padding-inline so thread and
   non-thread titles stay flush. */
.entry-list li.in-thread { position: relative; }
.entry-list li.in-thread::before {
  content: "";
  position: absolute;
  left: calc(-1 * var(--space-1));
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--thread-rail);
  border-radius: 2px;
}
/* Cap each run within its own content box: inset the bar by the li's vertical
   padding so consecutive threads (an `end` directly above the next `start`,
   with no standalone entry between them) show a clear gap instead of fusing
   into one continuous rail. Within a run, start.bottom (0) meets mid/end.top
   (0), so the rail stays unbroken. */
.entry-list li.thread-start::before { top: var(--space-2); border-top-left-radius: 4px; border-top-right-radius: 4px; }
.entry-list li.thread-end::before { bottom: var(--space-2); border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; }

/* ---- Footer: prev/next band over the site-nav band ---- */
/* The prev/next arrows render inside <footer> (entry pages only), directly
   above the global Home · About links — one cohesive cluster at the page
   bottom. The footer's own border-top is the separator above the cluster, so
   .entry-nav carries no border of its own. */
.entry-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
  font-size: 1.4rem;
  line-height: 1;
}
.entry-nav a {
  text-decoration: none;
  color: var(--fg-muted);
  padding: var(--space-1);
}
.entry-nav a:hover { color: var(--link-hover); }

.site-nav a {
  color: var(--fg-muted);
  text-decoration: none;
}
.site-nav a:hover { color: var(--link-hover); text-decoration: underline; }
.site-nav a + a::before {
  content: "·";
  color: var(--fg-muted);
  margin: 0 var(--space-2);
}

/* ---- Article ---- */
article .entry-date {
  margin: 0 0 var(--space-3);
}
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }

/* ---- Accessibility ---- */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  padding: var(--space-1) var(--space-2);
  background: var(--fg);
  color: var(--bg);
  z-index: 100;
}
.skip-link:focus { top: 0; }

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

.empty-state {
  color: var(--fg-muted);
  font-style: italic;
  padding: var(--space-3) 0;
}

/* ---- Mobile ---- */
@media (max-width: 768px) {
  html { font-size: 16px; }
  h1 { font-size: 1.5rem; }
  header, main, footer { padding-inline: var(--space-1); }
  pre { overflow-x: auto; }
}
