/* ---------- tokens ---------- */
:root {
  --bg: #ffffff;
  --bg-soft: #f5f6f4;
  --bg-card: #ffffff;
  --border: #e2e4df;
  --text: #16180f;
  --text-dim: #5d6154;
  --accent: #3a5fd9;
  --accent-soft: #e4eaff;
  --accent-text: #2545c4;
  --shadow: 0 1px 2px rgba(20, 24, 15, .06), 0 8px 24px rgba(20, 24, 15, .06);
  --radius: 14px;
  --wrap: 1080px;
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101210;
    --bg-soft: #171a16;
    --bg-card: #181b17;
    --border: #2b2f28;
    --text: #eef0ea;
    --text-dim: #a3a99b;
    --accent: #7c9dff;
    --accent-soft: #1a2450;
    --accent-text: #a8c1ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

:root[data-theme="dark"] {
  --bg: #101210;
  --bg-soft: #171a16;
  --bg-card: #181b17;
  --border: #2b2f28;
  --text: #eef0ea;
  --text-dim: #a3a99b;
  --accent: #7c9dff;
  --accent-soft: #1a2450;
  --accent-text: #a8c1ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }

a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  line-height: 1.2;
  letter-spacing: -.02em;
  margin: 0 0 .5em;
  font-weight: 700;
}

h1 { font-size: clamp(2rem, 5vw, 3rem); }
h2 { font-size: clamp(1.4rem, 3vw, 1.9rem); }
h3 { font-size: 1.2rem; }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 20px; }
.narrow { max-width: 720px; }

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: var(--bg); padding: 10px 16px; z-index: 100;
}
.skip:focus { left: 8px; top: 8px; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.nav {
  display: flex; align-items: center; gap: 20px;
  height: 62px;
}

.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 800; font-size: 1.05rem; letter-spacing: -.02em;
  color: var(--text); text-decoration: none; margin-right: auto;
}
.brand:hover { text-decoration: none; }

/* Accent is dark in light mode and light in dark mode, so --bg is always the
   readable text colour on top of it. Same trick for .btn and active tags. */
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--accent); color: var(--bg);
  display: grid; place-items: center; font-size: 15px;
}

.nav-links { display: flex; gap: 6px; align-items: center; }

.nav-links a {
  color: var(--text-dim); font-size: .95rem; font-weight: 500;
  padding: 7px 11px; border-radius: 8px;
}
.nav-links a:hover { color: var(--text); background: var(--bg-soft); text-decoration: none; }
.nav-links a[aria-current="page"] { color: var(--text); font-weight: 600; }

.theme-toggle {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text-dim);
  width: 36px; height: 36px; border-radius: 9px; cursor: pointer;
  display: grid; place-items: center; font-size: 15px; line-height: 1;
}
.theme-toggle:hover { color: var(--text); border-color: var(--text-dim); }

@media (max-width: 620px) {
  .nav { height: auto; padding: 12px 0; flex-wrap: wrap; }
  .nav-links a { padding: 6px 8px; font-size: .9rem; }
}

/* ---------- hero ---------- */
.hero {
  padding: 72px 0 48px;
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(900px 340px at 15% -10%, var(--accent-soft), transparent 70%),
    var(--bg);
}

.eyebrow {
  display: inline-block;
  font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent-text); background: var(--accent-soft);
  padding: 5px 11px; border-radius: 999px; margin-bottom: 18px;
}

.hero p.lede {
  font-size: 1.15rem; color: var(--text-dim); max-width: 620px; margin: 0 0 26px;
}

.btn {
  display: inline-block; padding: 11px 20px; border-radius: 10px;
  background: var(--accent); color: var(--bg); font-weight: 650; font-size: .95rem;
  border: 1px solid transparent; cursor: pointer;
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn-ghost {
  background: transparent; color: var(--text); border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-soft); filter: none; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- controls ---------- */
.controls {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  margin: 40px 0 22px;
}

.search {
  flex: 1; min-width: 220px;
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--bg-card);
  border-radius: 10px; padding: 0 12px;
}
.search:focus-within { border-color: var(--accent); }
.search input {
  flex: 1; border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: .95rem; padding: 10px 0; outline: none;
}
.search svg { flex-shrink: 0; opacity: .5; }

.tags { display: flex; gap: 7px; flex-wrap: wrap; }

/* The date sort sits beside the topic filters; a rule keeps the two groups
   from reading as one long row of buttons. */
.sorts { padding-left: 12px; border-left: 1px solid var(--border); }
@media (max-width: 620px) { .sorts { padding-left: 0; border-left: 0; } }

.tag {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text-dim);
  padding: 7px 13px; border-radius: 999px; font-size: .85rem; font-weight: 550;
  cursor: pointer; font-family: inherit;
}
.tag:hover { color: var(--text); border-color: var(--text-dim); }
.tag[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 650;
}

/* ---------- post grid ---------- */
.grid {
  display: grid; gap: 22px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  margin: 0 0 56px;
  padding: 0; list-style: none;
}

.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--text-dim); }

.card-art {
  height: 130px; display: grid; place-items: center;
  font-size: 2.4rem;
  background: linear-gradient(135deg, var(--accent-soft), var(--bg-soft));
  border-bottom: 1px solid var(--border);
}

.card-body { padding: 20px; display: flex; flex-direction: column; flex: 1; }

.card-meta {
  font-size: .78rem; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: .06em; font-weight: 650; margin-bottom: 9px;
}

.card h3 { margin: 0 0 8px; font-size: 1.15rem; }
.card h3 a { color: var(--text); }
.card h3 a:hover { color: var(--accent-text); text-decoration: none; }

/* The title link is stretched over the whole card, so a click anywhere
   opens the article. Keeping it a real anchor means the keyboard, the
   middle click and "open in new tab" all keep working. */
.card { position: relative; cursor: pointer; }
.card h3 a::after { content: ""; position: absolute; inset: 0; }
.card:hover h3 a { color: var(--accent-text); }
.card:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Briefly marks the card you have just published. */
.just-published { animation: land 2.6s ease-out; }
@keyframes land {
  0%, 60% { box-shadow: 0 0 0 3px var(--accent); }
  100% { box-shadow: 0 0 0 3px transparent; }
}
@media (prefers-reduced-motion: reduce) { .just-published { animation: none; } }

.card p { margin: 0 0 16px; color: var(--text-dim); font-size: .93rem; flex: 1; }

.card-foot {
  display: flex; gap: 6px; flex-wrap: wrap;
  border-top: 1px solid var(--border); padding-top: 13px;
}

.pill {
  font-size: .74rem; font-weight: 600; color: var(--text-dim);
  background: var(--bg-soft); border-radius: 6px; padding: 3px 8px;
}

.featured { grid-column: 1 / -1; }
.featured .card-art { height: 170px; font-size: 3rem; }
@media (min-width: 760px) {
  .featured { display: grid; grid-template-columns: 320px 1fr; }
  .featured .card-art { height: 100%; border-bottom: 0; border-right: 1px solid var(--border); }
  .featured h3 { font-size: 1.55rem; }
  .featured .card-body { padding: 28px; }
}

.empty {
  grid-column: 1 / -1; text-align: center; color: var(--text-dim);
  padding: 50px 20px; border: 1px dashed var(--border); border-radius: var(--radius);
}

/* ---------- newsletter ---------- */
.cta {
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 34px; text-align: center;
  margin-bottom: 56px;
}
.cta p { color: var(--text-dim); max-width: 460px; margin: 0 auto 20px; }
.cta form { display: flex; gap: 9px; max-width: 420px; margin: 0 auto; flex-wrap: wrap; }
.cta input {
  flex: 1; min-width: 200px; padding: 11px 14px; font: inherit; font-size: .95rem;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg-card); color: var(--text);
}
.cta input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-note { font-size: .85rem; color: var(--text-dim); margin-top: 12px; min-height: 1.2em; }

/* ---------- article ---------- */
.article-header {
  padding: 52px 0 30px;
  border-bottom: 1px solid var(--border);
  background: radial-gradient(700px 260px at 20% -20%, var(--accent-soft), transparent 70%);
}
.article-meta { color: var(--text-dim); font-size: .9rem; margin-bottom: 14px; }
.article-meta .dot { opacity: .5; margin: 0 7px; }

.prose { padding: 40px 0 20px; }
.prose h2 { margin-top: 2em; }
.prose h3 { margin-top: 1.6em; }
.prose p { margin: 0 0 1.25em; }
.prose ul, .prose ol { margin: 0 0 1.25em; padding-left: 1.3em; }
.prose li { margin-bottom: .5em; }
.prose strong { color: var(--text); font-weight: 650; }

.prose blockquote {
  margin: 1.8em 0; padding: 4px 0 4px 20px;
  border-left: 3px solid var(--accent);
  color: var(--text-dim); font-style: italic;
}

.callout {
  background: var(--bg-soft); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 18px 20px; margin: 1.8em 0;
}
.callout p:last-child { margin-bottom: 0; }
.callout strong { display: block; margin-bottom: 4px; }

.prose figure { margin: 2em 0; }
/* Lead picture, sitting between the title block and the opening paragraph. */
.prose .post-hero { margin: 0 0 2.2em; }
.prose .post-hero img { aspect-ratio: 16 / 9; object-fit: cover; }
.prose figure img { width: 100%; border-radius: var(--radius); border: 1px solid var(--border); }
.prose figcaption {
  margin-top: 9px; font-size: .87rem; color: var(--text-dim); text-align: center;
}

/* Cards fall back to an emoji, but take a picture when a post has one. */
.card-art img { width: 100%; height: 100%; object-fit: cover; }

.table-scroll { overflow-x: auto; margin: 1.8em 0; }
table { border-collapse: collapse; width: 100%; min-width: 440px; font-size: .93rem; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); }
th { font-weight: 650; background: var(--bg-soft); }

.article-foot {
  border-top: 1px solid var(--border); margin-top: 40px; padding: 26px 0 0;
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding-bottom: 56px;
}

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--border); background: var(--bg-soft);
  padding: 34px 0; margin-top: auto;
  color: var(--text-dim); font-size: .9rem;
}
.footer-inner { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: center; }
.footer-links { display: flex; gap: 16px; flex-wrap: wrap; }

body { display: flex; flex-direction: column; min-height: 100vh; }
main { flex: 1; }

/* ---------- about ---------- */
.stat-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px; margin: 32px 0;
}
.stat {
  border: 1px solid var(--border); background: var(--bg-card);
  border-radius: var(--radius); padding: 18px;
}
.stat b { display: block; font-size: 1.6rem; font-family: var(--font-display); letter-spacing: -.02em; }
.stat span { font-size: .85rem; color: var(--text-dim); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
