/* ---- Base ---- */
:root {
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --rule: #e5e5e5;
  --link: #1a4fa0;
  --bg: #fdfdfc;
  --code-bg: #f0f0ee;
  --pre-bg: #f5f5f3;
  --maxw: 860px;
}

/* Dark theme: applied when <html data-theme="dark">, or by system
   preference when no explicit choice has been made. */
:root[data-theme="dark"] {
  --ink: #e8e8e6;
  --muted: #9a9a96;
  --rule: #2c2c2c;
  --link: #7fb0ff;
  --bg: #161615;
  --code-bg: #262624;
  --pre-bg: #1e1e1d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e8e8e6;
    --muted: #9a9a96;
    --rule: #2c2c2c;
    --link: #7fb0ff;
    --bg: #161615;
    --code-bg: #262624;
    --pre-bg: #1e1e1d;
  }
}

html { color-scheme: light dark; }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

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

/* ---- Links ---- */
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Header / nav ---- */
header.site {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-bottom: 48px;
}
header.site .name {
  font-weight: 600;
  font-size: 18px;
  color: var(--ink);
}
header.site .name:hover { text-decoration: none; }
nav a {
  color: var(--muted);
  margin-left: 18px;
  font-size: 15px;
}
nav a:first-child { margin-left: 0; }
nav a.active { color: var(--ink); }

/* theme toggle button */
.theme-toggle {
  margin-left: 18px;
  background: none;
  border: 1px solid var(--rule);
  color: var(--muted);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  vertical-align: middle;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--muted); }
body { transition: background 0.15s ease, color 0.15s ease; }

/* ---- Intro block (home) ---- */
.intro {
  display: flex;
  gap: 28px;
  align-items: flex-start;
  margin-bottom: 40px;
}
.intro img {
  width: 170px;
  height: 170px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: #eee;
}
.intro h1 { margin: 0 0 4px; font-size: 24px; }
.intro .role { color: var(--muted); margin: 0 0 10px; }
.intro p { margin: 0 0 10px; }

.contact { font-size: 15px; }
.contact a { margin-right: 14px; }

/* ---- Section headings ---- */
h2.section {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 8px;
  margin: 48px 0 20px;
}

/* ---- Post / project list ---- */
.list { list-style: none; padding: 0; margin: 0; }
.list li { margin-bottom: 22px; }
.list .title { font-weight: 600; color: var(--ink); }
.list .title:hover { color: var(--link); }
.list .meta { color: var(--muted); font-size: 14px; }
.list .desc { margin: 2px 0 0; color: #333; }

/* compact dated list (writing index) */
.entries { list-style: none; padding: 0; margin: 0; }
.entries li {
  display: flex;
  gap: 18px;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
}
.entries .date {
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 110px;
}

/* ---- Article (single post) ---- */
article h1 { font-size: 28px; margin: 0 0 6px; line-height: 1.25; }
article .post-meta { color: var(--muted); font-size: 15px; margin-bottom: 32px; }
article h2 { font-size: 21px; margin: 36px 0 12px; }
article h3 { font-size: 18px; margin: 28px 0 10px; }
article p, article li { line-height: 1.7; }
article img { max-width: 100%; border-radius: 6px; }
.video {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 */
  height: 0;
  margin: 28px 0;
  border-radius: 6px;
  overflow: hidden;
}
.video iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0; }
img.logo { width: 120px; }

/* wide / banner image: break out beyond the text column, centered on viewport */
article img.banner {
  display: block;
  width: min(1100px, 94vw);
  margin-left: 50%;
  transform: translateX(-50%);
  margin-top: 28px;
  margin-bottom: 28px;
}
article blockquote {
  border-left: 3px solid var(--rule);
  margin: 20px 0;
  padding: 4px 18px;
  color: #444;
}
article pre {
  background: var(--pre-bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 14px 16px;
  overflow-x: auto;
  font-size: 14px;
}
article code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
}
article pre code { background: none; padding: 0; }

.back { display: inline-block; margin-bottom: 32px; color: var(--muted); font-size: 15px; }
.more { margin-top: 16px; font-size: 15px; }
.page-intro { color: var(--muted); margin: -8px 0 24px; }
article .caption { color: var(--muted); font-size: 14px; margin-top: -8px; }
article .tags { color: var(--muted); font-size: 14px; margin-top: 32px; }

/* ---- Article extras (rich post: résumé-that-compiles & friends) ---- */
article .lede {
  font-size: 18px;
  line-height: 1.6;
  color: var(--muted);
  margin: 0 0 8px;
}
article figure { margin: 28px 0; text-align: center; }
article figure img {
  border: 1px solid var(--rule);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.07);
}
article figcaption { color: var(--muted); font-size: 14px; margin-top: 10px; }

/* call-out box for design decisions */
article .decision {
  border-left: 3px solid var(--link);
  background: var(--pre-bg);
  border-radius: 0 6px 6px 0;
  padding: 10px 18px;
  margin: 22px 0;
}
article .decision b { color: var(--link); }

/* horizontal pipeline diagram */
article .pipe {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 8px; justify-content: center;
  font-size: 13px; margin: 26px 0;
}
article .pipe .box {
  background: var(--bg); border: 1px solid var(--rule);
  border-radius: 6px; padding: 8px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
article .pipe .arr { color: var(--muted); }

/* tables */
article table { border-collapse: collapse; width: 100%; margin: 20px 0; font-size: 15px; }
article th, article td { border: 1px solid var(--rule); padding: 7px 10px; text-align: left; }
article th { background: var(--pre-bg); }

/* terminal / log block (dark in both themes) */
article .term {
  background: #1e2128; color: #d7dae0;
  border-radius: 6px; padding: 16px 18px;
  overflow-x: auto; font-size: 13px; line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin: 22px 0;
}
article .term .g { color: #7ee787; }
article .term .y { color: #e3b341; }
article .term .m { color: #8b8b8b; }

/* flow pill */
article .pill {
  display: inline-block; font-size: 12px; font-weight: 600;
  padding: 1px 9px; border-radius: 999px;
  background: var(--code-bg); color: var(--link);
}

/* extra terminal colors */
article .term .r { color: #f87171; }
article .term .b { color: #79c0ff; }
article .term .a { color: #ffa657; }

/* terminal with a macOS-style title bar */
article .term-window { margin: 22px 0; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
article .term-window .term { margin: 0; border-radius: 0; }
article .term-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; background: #2a2d34;
}
article .term-bar .dot { width: 11px; height: 11px; border-radius: 50%; }
article .term-bar .dot-r { background: #ff5f57; }
article .term-bar .dot-y { background: #febc2e; }
article .term-bar .dot-g { background: #28c840; }
article .term-title { flex: 1; text-align: center; font: 12px ui-monospace, Menlo, monospace; color: #8b8b8b; }

/* card grid (comparisons, design principles) */
article .cardgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 22px 0; }
article .card { background: var(--pre-bg); border: 1px solid var(--rule); border-radius: 8px; padding: 16px 18px; }
article .card p { font-size: 14px; color: var(--muted); margin: 0 0 8px; }
article .card p:last-child { margin-bottom: 0; }
article .card-label {
  font: 600 11px ui-monospace, Menlo, monospace;
  text-transform: uppercase; letter-spacing: .12em; margin-bottom: 8px;
}
article .card-label.bad { color: #e5534b; }
article .card-label.good { color: #3fb950; }

/* numbered workflow steps */
article .steps { margin: 28px 0; }
article .step { display: flex; gap: 16px; padding: 14px 0; }
article .step-num {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 10px;
  background: var(--pre-bg); border: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: center;
  font: 600 13px ui-monospace, Menlo, monospace; color: var(--link);
}
article .step-body { flex: 1; }
article .step-title { font-weight: 600; margin-bottom: 4px; }
article .step-desc { font-size: 14px; color: var(--muted); margin: 0; line-height: 1.6; }
article .step-cmd {
  display: inline-block; margin-top: 8px; padding: 2px 10px;
  font: 12px ui-monospace, Menlo, monospace; color: var(--link);
  background: var(--code-bg); border: 1px solid var(--rule); border-radius: 6px;
}

/* labeled left-to-right flow rows */
article .flow { background: var(--pre-bg); border: 1px solid var(--rule); border-radius: 8px; padding: 18px 20px; margin: 22px 0; }
article .flow-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
article .flow-row:last-child { margin-bottom: 0; }
article .flow-label { font: 11px ui-monospace, Menlo, monospace; color: var(--muted); width: 80px; flex-shrink: 0; }
article .flow .box {
  flex: 1; min-width: 90px; text-align: center; padding: 6px 10px;
  font: 12px ui-monospace, Menlo, monospace;
  background: var(--bg); border: 1px solid var(--rule); border-radius: 6px;
}
article .flow .arr { color: var(--muted); flex-shrink: 0; }

/* two-pane file anatomy */
article .anatomy { border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; margin: 22px 0; background: var(--pre-bg); }
article .anatomy-header { padding: 10px 16px; background: var(--code-bg); border-bottom: 1px solid var(--rule); font: 13px ui-monospace, Menlo, monospace; }
article .anatomy-body { display: flex; }
article .anatomy-sections { width: 170px; flex-shrink: 0; border-right: 1px solid var(--rule); font: 12px/1 ui-monospace, Menlo, monospace; }
article .anatomy-section { padding: 10px 14px; border-bottom: 1px solid var(--rule); color: var(--muted); }
article .anatomy-section:last-child { border-bottom: none; }
article .anatomy-section.active { color: var(--link); background: var(--code-bg); }
article .anatomy-content { flex: 1; padding: 14px 18px; font-size: 13px; color: var(--muted); line-height: 1.7; }
article .anatomy-content .sec-title {
  font: 600 12px ui-monospace, Menlo, monospace; color: var(--link);
  text-transform: uppercase; letter-spacing: .08em; margin-bottom: 8px;
}

/* stat cards */
article .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 22px 0; }
article .stat { background: var(--pre-bg); border: 1px solid var(--rule); border-radius: 8px; padding: 18px; text-align: center; }
article .stat-num { font: 800 34px ui-monospace, Menlo, monospace; color: var(--link); line-height: 1.1; margin-bottom: 6px; }
article .stat-label { font-size: 13px; color: var(--muted); }

/* ---- Sidenotes (margin annotations, eieio/Tufte style) ----
   Authoring (inline, inside a raw-HTML <p>):
   <span class="sn"><label class="sn-pill" for="sn-UNIQUE"></label><input
     class="sn-toggle" type="checkbox" id="sn-UNIQUE"><span class="sn-note">
     The aside.</span></span>
   Numbering is automatic (CSS counters). Wide screens: note floats in the
   right margin beside its anchor. Narrow: tap the numbered pill to expand
   the note inline. No JS. */
article { counter-reset: sidenote; }
article .sn-toggle { display: none; }
article .sn-pill { counter-increment: sidenote; cursor: pointer; }
article .sn-pill::after {
  content: counter(sidenote);
  display: inline-block;
  font: 600 10px/1.5 ui-monospace, Menlo, monospace;
  color: var(--link);
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0 5px;
  margin-left: 2px;
  vertical-align: super;
}
article .sn-note { display: none; }
article .sn-note::before {
  content: counter(sidenote);
  font: 600 10px/1.6 ui-monospace, Menlo, monospace;
  color: var(--link);
  margin-right: 6px;
}
/* narrow: pill toggles the note open inline */
article .sn-toggle:checked ~ .sn-note {
  display: block;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--muted);
  background: var(--pre-bg);
  border-left: 2px solid var(--link);
  border-radius: 0 6px 6px 0;
  padding: 8px 12px;
  margin: 10px 0;
}
/* wide: notes hang in the right margin, aligned to their anchor line */
@media (min-width: 1440px) {
  article .sn-note,
  article .sn-toggle:checked ~ .sn-note {
    display: block;
    float: right;
    clear: right;
    width: 280px;
    margin-right: -310px;
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 13px;
    line-height: 1.55;
    color: var(--muted);
    background: none;
    border-left: 2px solid var(--rule);
    border-radius: 0;
    padding: 0 0 0 10px;
  }
  article .sn-pill { cursor: default; pointer-events: none; }
}

/* colophon (post sign-off) */
article .colophon {
  margin-top: 40px;
  border-top: 1px solid var(--rule);
  padding-top: 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

/* ---- Footer ---- */
footer.site {
  margin-top: 72px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 14px;
}

/* ---- Layout debug guides (toggle: press "g", or add #debug to the URL) ---- */
html.debug body::before {
  content: "";
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: var(--maxw);
  max-width: 100%;
  /* outer line = content column edge; inset line = text edge (24px padding) */
  border-left: 1px solid rgba(255, 64, 64, 0.55);
  border-right: 1px solid rgba(255, 64, 64, 0.55);
  box-shadow: inset 24px 0 0 -23px rgba(64, 128, 255, 0.55),
              inset -24px 0 0 -23px rgba(64, 128, 255, 0.55);
  pointer-events: none;
  z-index: 9998;
}
html.debug body::after {
  content: "debug guides — press g to hide";
  position: fixed;
  top: 8px;
  left: 8px;
  font: 12px/1 ui-monospace, monospace;
  color: #fff;
  background: rgba(255, 64, 64, 0.9);
  padding: 4px 7px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 9999;
}
html.debug .wrap * { outline: 1px solid rgba(64, 128, 255, 0.18); }

/* ---- Mobile ---- */
@media (max-width: 640px) {
  body { font-size: 16px; }
  .wrap { padding: 28px 18px 64px; }

  /* header: tighter, room for all four links + toggle on one or two lines */
  header.site { margin-bottom: 32px; gap: 6px 14px; }
  nav a { margin-left: 13px; font-size: 14px; }
  .theme-toggle { margin-left: 13px; width: 28px; height: 28px; }

  /* intro: stacked, photo still prominent */
  .intro { flex-direction: column; gap: 16px; }
  .intro img { width: 120px; height: 120px; }
  .intro h1 { font-size: 22px; }

  /* lists */
  .entries li { flex-direction: column; gap: 2px; }
  .entries .date { min-width: 0; }

  /* article typography */
  article h1 { font-size: 23px; }
  article h2 { font-size: 19px; margin-top: 30px; }
  article .lede { font-size: 16.5px; }
  article pre { font-size: 13px; padding: 12px 14px; }

  /* tables scroll instead of blowing out the viewport */
  article table { display: block; overflow-x: auto; font-size: 14px; }

  /* terminal + diagram blocks: tighter */
  article .term { font-size: 12px; padding: 12px 14px; }
  article .pipe { font-size: 12px; gap: 6px; }
  article .flow { padding: 14px; }
  article .flow-label { width: 100%; }
  article .flow .box { min-width: 0; padding: 5px 8px; font-size: 11px; }

  /* grids collapse to a single column */
  article .cardgrid, article .stats { grid-template-columns: 1fr; }
  article .stat { padding: 14px; }
  article .stat-num { font-size: 28px; }

  /* anatomy widget stacks */
  article .anatomy-body { flex-direction: column; }
  article .anatomy-sections { width: 100%; display: flex; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--rule); }
  article .anatomy-section { border-bottom: none; padding: 8px 10px; }

  /* steps + callouts */
  article .step { gap: 12px; padding: 10px 0; }
  article .step-num { width: 34px; height: 34px; font-size: 12px; }
  article .decision { padding: 8px 14px; }
  article .colophon { font-size: 13px; }

  /* banner images shouldn't overhang on small screens */
  article img.banner { width: 100%; margin-left: 0; transform: none; }
}
