:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --text: #1c1917;
  --muted: #57534e;
  --border: #e7e5e4;
  --accent: #0b6bcb;
  --accent-contrast: #ffffff;
  --radius: 10px;
  --maxw: 880px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1113;
    --surface: #17191c;
    --text: #ececea;
    --muted: #a3a3a0;
    --border: #2a2d31;
    --accent: #5aa9ff;
    --accent-contrast: #0b0d0f;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1113;
  --surface: #17191c;
  --text: #ececea;
  --muted: #a3a3a0;
  --border: #2a2d31;
  --accent: #5aa9ff;
  --accent-contrast: #0b0d0f;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.65 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-contrast); padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: 8px; top: 8px; }

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

/* Header */
header.site {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
header.site .wrap { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 16px; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
nav ul { display: flex; gap: 20px; list-style: none; margin: 0; padding: 0; align-items: center; flex-wrap: wrap; }
nav a { color: var(--muted); text-decoration: none; font-size: .95rem; }
nav a:hover { color: var(--text); }
#theme-toggle {
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; padding: 4px 10px; cursor: pointer; font: inherit; font-size: .85rem;
}
#theme-toggle:hover { color: var(--text); }

/* Sections */
section { padding: 64px 0 8px; }
section h2 { font-size: 1.5rem; letter-spacing: -.01em; margin: 0 0 20px; }
.hero { padding: 88px 0 24px; }
.hero h1 { font-size: clamp(2.2rem, 6vw, 3.4rem); line-height: 1.1; margin: 0 0 12px; letter-spacing: -.03em; }
.hero .role { font-size: 1.2rem; color: var(--muted); margin: 0 0 20px; }
.hero p.lede { max-width: 62ch; margin: 0 0 28px; }
.cta { display: flex; gap: 12px; flex-wrap: wrap; }
.btn {
  display: inline-block; padding: 10px 18px; border-radius: 8px; font-weight: 600;
  text-decoration: none; border: 1px solid var(--accent);
}
.btn.primary { background: var(--accent); color: var(--accent-contrast); }
.btn.ghost { color: var(--accent); }
.btn:hover { filter: brightness(1.08); }

/* Cards & grids */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.card h3 { margin: 0 0 8px; font-size: 1.05rem; }
.card p { margin: 0; color: var(--muted); font-size: .97rem; }
.card ul { margin: 0; padding-left: 1.1rem; color: var(--muted); font-size: .97rem; }
.card a.more { display: inline-block; margin-top: 12px; font-weight: 600; font-size: .95rem; }

.tags { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 0; }
.tags li {
  border: 1px solid var(--border); background: var(--bg);
  padding: 3px 10px; border-radius: 999px; font-size: .85rem; color: var(--muted);
}

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); }
.timeline li { padding: 0 0 22px 20px; position: relative; }
.timeline li::before {
  content: ""; position: absolute; left: -7px; top: 8px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--accent);
}
.timeline strong { display: block; }
.timeline span { color: var(--muted); font-size: .95rem; }

/* Article pages */
article { padding: 56px 0 40px; }
article h1 { font-size: 2rem; letter-spacing: -.02em; margin: 0 0 8px; }
article h2 { margin-top: 40px; font-size: 1.3rem; }
article pre {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; overflow-x: auto; font-size: .9rem; line-height: 1.5;
}
article code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.note { border-left: 4px solid var(--accent); padding: 8px 16px; background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0; color: var(--muted); }

footer { margin-top: 64px; border-top: 1px solid var(--border); padding: 28px 0 40px; color: var(--muted); font-size: .9rem; }

@media (max-width: 620px) {
  nav ul { gap: 12px; font-size: .9rem; }
  header.site .wrap { height: auto; padding-top: 10px; padding-bottom: 10px; flex-wrap: wrap; }
  .hero { padding-top: 56px; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
@media print {
  header.site, #theme-toggle, .cta { display: none; }
  body { background: #fff; color: #000; }
}

.sub { margin-top: 32px; }
.notfound { padding-top: 96px; padding-bottom: 40px; }

.card ul.tags { padding-left: 0; margin-top: 4px; }

/* Architecture diagram (inline SVG) */
.diagram { display: block; width: 100%; max-width: 440px; height: auto; margin: 24px auto; }
.dg-box { fill: var(--surface); stroke: var(--border); stroke-width: 1.5; }
.dg-box.hl { stroke: var(--accent); stroke-width: 2; }
.dg-title { fill: var(--text); font: 600 15px system-ui, -apple-system, "Segoe UI", sans-serif; }
.dg-sub { fill: var(--muted); font: 13px system-ui, -apple-system, "Segoe UI", sans-serif; }
.dg-line { stroke: var(--accent); stroke-width: 2; fill: none; }
.dg-arrow { fill: var(--accent); }
.lesson { margin: 0 0 18px; }
.lesson strong { display: block; }

/* Hero with headshot */
.hero-grid { display: flex; align-items: center; gap: 40px; justify-content: space-between; }
.hero-text { flex: 1 1 auto; min-width: 0; }
.headshot {
  flex: 0 0 auto; width: 200px; height: 200px; border-radius: 50%;
  object-fit: cover; border: 3px solid var(--border);
}
@media (max-width: 620px) {
  .hero-grid { flex-direction: column-reverse; align-items: flex-start; gap: 24px; }
  .headshot { width: 140px; height: 140px; }
}
