/*
 * Text-first, minimal. One neutral typeface (the platform's own UI font),
 * no web fonts, no animations.
 *
 * Font stack: platform UI fonts are named explicitly *before* the generic
 * `system-ui`, because `system-ui` on some Windows locales resolves to a CJK
 * font with poor Latin glyphs. Renders as SF Pro (Apple), Segoe UI (Windows),
 * Roboto (Android/ChromeOS), Ubuntu/Cantarell/Noto (Linux).
 */
:root {
  --bg: #fcfcfb;
  --fg: #1a1a1a;
  --muted: #5f5f5f; /* 6.3:1 on --bg (WCAG AA for body text) */
  --rule: #e4e4e1;
  --accent: #1f4e8c; /* 8.3:1 on --bg */
  --danger: #a3221b;
  --ok-bg: #eef4ec;
  --err-bg: #fbeceb;
  --measure: 36rem; /* ~68 characters per line at 17px */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans",
    "Helvetica Neue", Arial, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151515;
    --fg: #e6e4e1;
    --muted: #a3a09b; /* 7.4:1 on --bg */
    --rule: #2c2c2a;
    --accent: #8fb6ec;
    --danger: #f08a82;
    --ok-bg: #1d2a1c;
    --err-bg: #331c1a;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0 auto;
  max-width: calc(var(--measure) + 3rem);
  padding: 0 1.5rem 6rem;
  background: var(--bg);
  color: var(--fg);
  font: 400 1.0625rem/1.65 var(--font);
  font-kerning: normal;
}
body.admin { max-width: 56rem; font-size: 1rem; line-height: 1.5; }

a { color: var(--accent); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
time, .meta, .count { font-variant-numeric: tabular-nums; }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 1rem; top: 1rem; background: var(--bg); padding: 0.25rem 0.5rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- header ---------- */
.site-header {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.5rem 1.5rem;
  padding: 2.75rem 0 1.25rem; margin-bottom: 3rem; border-bottom: 1px solid var(--rule);
  font-size: 0.9375rem;
}
.site-title { font-weight: 600; color: var(--fg); text-decoration: none; letter-spacing: -0.005em; }
.site-header nav { display: flex; flex-wrap: wrap; gap: 1.25rem; align-items: baseline; }
.site-header nav a { color: var(--muted); text-decoration: none; }
.site-header nav a:hover { color: var(--fg); text-decoration: underline; }
.badge { font-weight: 400; font-size: 0.75rem; color: var(--muted); border: 1px solid var(--rule); border-radius: 3px; padding: 0 0.35rem; margin-left: 0.35rem; }

.lede { color: var(--muted); margin: 0 0 3rem; }
.page-header { margin-bottom: 3rem; }
.page-title { font-size: 1.5rem; line-height: 1.25; font-weight: 600; letter-spacing: -0.015em; margin: 0 0 0.25rem; }
.page-header .meta { margin: 0; }
.empty { color: var(--muted); }
.back { margin-top: 4rem; font-size: 0.9375rem; color: var(--muted); }

/* ---------- posts (stream and single) ---------- */
.stream .entry + .entry {
  margin-top: 4rem;
  padding-top: 4rem;
  border-top: 1px solid var(--rule);
}
.entry > header { margin-bottom: 1.75rem; }
.entry-title {
  margin: 0 0 0.35rem;
  font-size: 1.5rem; line-height: 1.25; font-weight: 600; letter-spacing: -0.017em;
  text-wrap: balance;
}
h1.entry-title { font-size: 1.875rem; letter-spacing: -0.021em; }
.entry-title a { color: inherit; text-decoration: none; }
.entry-title a:hover { text-decoration: underline; text-decoration-thickness: 1px; }
/* Land below the top edge when following a /#post-slug link. */
.stream .entry { scroll-margin-top: 1.5rem; }

.meta { margin: 0; font-size: 0.875rem; color: var(--muted); }
.entry-footer { margin-top: 2rem; }
.tags { display: flex; flex-wrap: wrap; gap: 0.25rem 0.9rem; list-style: none; margin: 0; padding: 0; font-size: 0.875rem; }
.tags a { color: var(--muted); text-decoration: none; }
.tags a:hover { color: var(--accent); text-decoration: underline; }

.tag-index { list-style: none; padding: 0; margin: 0; columns: 2 12rem; }
.tag-index li { margin-bottom: 0.5rem; break-inside: avoid; }
.tag-index a { text-decoration: none; }
.tag-index a:hover { text-decoration: underline; }
.count { color: var(--muted); font-size: 0.8125rem; margin-left: 0.35rem; }

/* ---------- prose ---------- */
.prose { overflow-wrap: break-word; hyphens: manual; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose pre, .prose table { margin: 0 0 1.15em; }
.prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  margin: 2em 0 0.6em; line-height: 1.3; font-weight: 600; letter-spacing: -0.01em;
}
.prose h2 { font-size: 1.25rem; }
.prose h3 { font-size: 1.125rem; }
.prose h4, .prose h5, .prose h6 { font-size: 1rem; }
/* In the stream, body headings are h3+ (title is h2); keep their sizes modest. */
.stream .prose h3 { font-size: 1.1875rem; }
.stream .prose h4 { font-size: 1.0625rem; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: 0.3em; }
.prose li > ul, .prose li > ol { margin: 0.3em 0 0; }
.prose blockquote { margin-left: 0; padding-left: 1rem; border-left: 2px solid var(--rule); color: var(--muted); }
.prose img { max-width: 100%; height: auto; display: block; margin: 1.5em 0; }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5em 0; }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 0.9375rem; }
.prose th, .prose td { border-bottom: 1px solid var(--rule); padding: 0.4rem 0.9rem 0.4rem 0; text-align: left; }
.prose th { font-weight: 600; }
code, pre { font-family: var(--mono); font-size: 0.875em; }
:not(pre) > code { background: color-mix(in srgb, var(--rule) 60%, transparent); padding: 0.1em 0.3em; border-radius: 3px; }
pre { overflow-x: auto; padding: 1rem 1.1rem; background: color-mix(in srgb, var(--rule) 45%, transparent); border-radius: 4px; line-height: 1.5; tab-size: 2; }

/* ---------- admin ---------- */
.flash { background: var(--ok-bg); padding: 0.6rem 0.9rem; border-radius: 4px; }
.error { background: var(--err-bg); color: var(--danger); padding: 0.6rem 0.9rem; border-radius: 4px; }
.field-error { color: var(--danger); margin: -0.25rem 0 0.5rem; font-size: 0.9rem; }
.hint { color: var(--muted); font-weight: 400; font-size: 0.9em; }
.title-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.title-row .page-title, body.admin .page-title { margin-bottom: 1.5rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
th, td { text-align: left; vertical-align: top; padding: 0.6rem 0.75rem 0.6rem 0; border-bottom: 1px solid var(--rule); }
th { font-weight: 600; color: var(--muted); font-size: 0.8125rem; }
td .tags { color: var(--muted); font-size: 0.8125rem; margin-top: 0.15rem; }
.status { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.status.published { color: var(--accent); }
.status.draft { color: var(--muted); }

.stack { display: flex; flex-direction: column; gap: 0.35rem; }
.stack label { font-weight: 600; margin-top: 0.9rem; }
.narrow { max-width: 22rem; }
input, textarea, button, .button { font: inherit; color: inherit; }
input, textarea {
  width: 100%; padding: 0.55rem 0.65rem; border: 1px solid color-mix(in srgb, var(--fg) 30%, transparent);
  border-radius: 4px; background: var(--bg);
}
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }
.editor textarea { font-family: var(--mono); font-size: 0.9375rem; line-height: 1.55; min-height: 20rem; resize: vertical; }
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-top: 1.25rem; }
button, .button {
  padding: 0.5rem 1rem; border: 1px solid color-mix(in srgb, var(--fg) 35%, transparent); border-radius: 4px;
  background: transparent; cursor: pointer; text-decoration: none; display: inline-block; line-height: 1.4;
}
button.primary, .button { background: var(--accent); border-color: var(--accent); color: var(--bg); }
button.danger { background: var(--danger); border-color: var(--danger); color: var(--bg); }
button.link { border: 0; padding: 0; background: none; color: var(--muted); text-decoration: underline; }
form.inline { display: inline; }
.secondary-actions { margin-top: 2rem; font-size: 0.9375rem; }
a.danger { color: var(--danger); }
body.admin .entry { margin-top: 2rem; }

/* ---------- small screens ---------- */
@media (max-width: 34rem) {
  body { padding: 0 1.25rem 4rem; }
  .site-header { padding-top: 1.75rem; margin-bottom: 2.25rem; }
  .stream .entry + .entry { margin-top: 3rem; padding-top: 3rem; }
  .entry-title { font-size: 1.375rem; }
  h1.entry-title { font-size: 1.625rem; }
  th:nth-child(4), td:nth-child(4) { display: none; }
}
