/* ============================================================
   site.css — shared design system for jeremiahdillon.com
   Loaded by every page (homepage, /writing/, every essay).
   Page-specific styles live in the homepage's inline <style>,
   the /writing/ index's inline <style>, and writing/article.css.

   Aesthetic: terminal-leaning and typographic. Greyscale only,
   hairline rules, no shadows or gradients, near-square corners.
   Inter for reading; JetBrains Mono for headings, navigation,
   labels and metadata. Light and dark themes follow the
   visitor's OS setting unless they choose one (theme button).
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ---------- TOKENS ----------
   Each colour is light-dark(<light>, <dark>). The theme follows the
   OS unless the visitor picks one with the theme button, which sets
   data-theme="light" | "dark" on <html> (site.js; applied before
   first paint by the inline script in each page's <head>). */
:root {
  color-scheme: light dark;

  --bg:            light-dark(#fbfbfb, #0c0c0c);
  --bg-weak:       light-dark(#f4f4f4, #141414);   /* code blocks          */
  --bg-weaker:     light-dark(#ececec, #222222);   /* secondary buttons    */
  --border:        light-dark(#e0e0e0, #2a2a2a);   /* hairline rules       */
  --border-strong: light-dark(#c8c8c8, #464646);
  --text:          light-dark(#161616, #fafafa);   /* headings, emphasis   */
  --text-2:        light-dark(#4a4a4a, #b4b4b4);   /* body copy            */
  --text-3:        light-dark(#6b6b6b, #8f8f8f);   /* metadata, muted copy */
  --text-4:        light-dark(#8f8f8f, #626262);   /* decorative only: brackets, separators */
  --invert-bg:     light-dark(#161616, #fafafa);   /* primary button       */
  --invert-hover:  light-dark(#3a3a3a, #d6d6d6);
  --invert-text:   light-dark(#fafafa, #0c0c0c);
  --focus:         light-dark(#3b5cf6, #6b8fff);

  /* Syntax tokens (code blocks) */
  --tok-key:       light-dark(#2f4fd8, #8fa8ff);
  --tok-str:       light-dark(#a24a12, #f2a66b);
  --tok-cmt:       light-dark(#686868, #8a8a8a);

  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --sidebar:     15rem;   /* left rail on wide screens            */
  --page-max:    90rem;   /* whole page frame on wide screens      */
  --content-max: 68rem;   /* homepage content column              */
  --measure:     46rem;   /* reading column for essays            */
  --gutter:      2.5rem;
  --radius:      3px;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

/* ---------- BASE ---------- */
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

body {
  background: var(--bg);
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }
strong { color: var(--text); font-weight: 600; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
::selection { background: var(--text); color: var(--bg); }

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 200;
  padding: 0.5rem 0.75rem;
  background: var(--invert-bg);
  color: var(--invert-text);
  font: 500 0.8125rem/1 var(--font-mono);
  text-decoration: none;
}
.skip-link:focus { top: 1rem; }

/* Mono micro-label: small, uppercase, tracked */
.label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}

/* Content column. Left-aligned in the content area on wide screens;
   below 1024px it is simply full width with gutters. */
.wrap {
  max-width: var(--content-max);
  margin-left: var(--gutter);
  margin-right: var(--gutter);
}

/* ---------- SITE HEADER / NAV ----------
   Narrow screens: a sticky top bar.
   ≥1024px: a sticky left rail with bracketed, numbered links. */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 3.5rem;
  padding: 0 var(--gutter);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--text);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  white-space: nowrap;
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  background: var(--text);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  list-style: none;
}
.site-nav a {
  display: inline-flex;
  gap: 0.6rem;
  padding: 0.2rem 0;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-3);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s;
}
.site-nav .idx { color: var(--text-4); transition: color 0.15s; }
.site-nav a:hover,
.site-nav a[aria-current] { color: var(--text); }
.site-nav a:hover .idx,
.site-nav a[aria-current] .idx { color: var(--text-3); }

/* ≥1024px: the page is a grid capped at --page-max and centered,
   so on very wide monitors the sidebar, content and (on essays)
   the Contents rail stay together instead of drifting apart.
   Columns: rail | content [| contents, added by article.js].
   The rail holds the site nav (sticky at the top of the viewport)
   and, at the end of the page, the site footer. */
@media (min-width: 1024px) {
  body {
    display: grid;
    grid-template-columns: var(--sidebar) minmax(0, 1fr);
    grid-template-rows: 1fr;
    max-width: var(--page-max);
    min-height: 100vh;
    margin: 0 auto;
  }
  body > main { grid-column: 2; grid-row: 1; }
  .wrap { margin-left: 0; }
  .site-header {
    grid-column: 1;
    grid-row: 1;
    align-self: start;
    position: sticky;
    top: 0;
    height: auto;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 2.5rem;
    padding: 1.5rem 1.5rem;
    background: transparent;
    border-bottom: 0;
  }
  .site-nav ul { flex-direction: column; gap: 0.45rem; }
  .site-nav a { font-size: 0.875rem; }
}

@media (max-width: 700px) {
  :root { --gutter: 1.25rem; }
  .brand-name { display: none; }
  .site-nav ul { gap: 0.25rem 1rem; }
  .site-nav .idx { display: none; }
}

/* ---------- BREADCRUMB (/writing/ and essays; mirrored in BreadcrumbList JSON-LD) ---------- */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
  margin-bottom: 2rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-3);
}
.breadcrumb a { color: var(--text-3); text-decoration: none; transition: color 0.15s; }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb .sep { color: var(--text-4); }
.breadcrumb [aria-current="page"] { color: var(--text-2); }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 2.25rem;
  padding: 0 1rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-primary { background: var(--invert-bg); color: var(--invert-text); }
.btn-primary:hover { background: var(--invert-hover); }
.btn-secondary { background: var(--bg-weaker); color: var(--text); }
.btn-secondary:hover { border-color: var(--border-strong); }
.btn .chev { color: var(--text-3); font-family: var(--font-mono); }

/* ---------- ESSAY LIST (homepage + /writing/) ---------- */
.essay-list { display: grid; }
.essay-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1.5rem;
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border);
  align-items: start;
}
.essay-item:first-child { border-top: 1px solid var(--border); }
.essay-title-link { display: block; color: inherit; text-decoration: none; }
.essay-title {
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text);
  margin-bottom: 0.3rem;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
  transition: text-decoration-color 0.15s;
}
.essay-title-link:hover .essay-title { text-decoration-color: currentColor; }
.essay-desc { font-size: 0.9rem; color: var(--text-3); line-height: 1.55; }
.essay-meta-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
  padding-top: 0.15rem;
}
.essay-date,
.essay-alts {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-3);
  white-space: nowrap;
}
.essay-alts { display: flex; align-items: center; gap: 0.5rem; }
.essay-alts .sep { color: var(--text-4); }
.essay-alt { color: var(--text-3); text-decoration: none; transition: color 0.15s; }
.essay-alt:hover { color: var(--text); }

@media (max-width: 600px) {
  .essay-item { grid-template-columns: 1fr; gap: 0.6rem; }
  .essay-meta-right {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 1rem;
    padding-top: 0;
  }
}

/* ---------- CODE WINDOW ----------
   A bordered block with a tab bar (filename + Copy), used on the
   homepage "Why?" section and in essays. */
.code-window {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-weak);
  overflow: hidden;
}
.code-titlebar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}
.code-filename {
  padding: 0.65rem 1rem;
  color: var(--text);
  box-shadow: inset 0 -1px 0 var(--text);   /* active-tab underline */
}
.code-copy {
  padding: 0 1rem;
  font: inherit;
  color: var(--text-3);
  background: none;
  border: 0;
  cursor: pointer;
  transition: color 0.15s;
}
.code-copy:hover { color: var(--text); }
.code-body { padding: 1.25rem 1.25rem; overflow-x: auto; }
.code-body pre,
.code-body code {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.7;
  color: var(--text);
  white-space: pre;
  background: none;
  border: 0;
  padding: 0;
}

/* Syntax tokens — used in <pre><code> and .code-window */
.tok-key { color: var(--tok-key); }
.tok-lbl { color: var(--tok-key); font-weight: 700; }
.tok-str { color: var(--tok-str); }
.tok-cmt { color: var(--tok-cmt); }
.tok-hd  { color: var(--tok-cmt); font-weight: 700; }
.tok-pun { color: var(--text-3); }

/* ---------- FOOTER ----------
   Social links, the theme and Markdown buttons, and the colophon.
   Like opencode.ai, it is an ordinary block at the very end of the
   page, so it only comes into view once you scroll to the bottom
   (or straight away on a page shorter than the window).
   ≥1024px: it sits at the bottom of the left rail column.
   <1024px: it stacks at the end of the page, one link per line. */
.site-footer {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  margin: 0 var(--gutter);
  padding: 2rem 0 2.5rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.875rem;
}
.footer-nav ul { display: flex; flex-direction: column; list-style: none; }
.footer-nav a {
  display: inline-flex;
  gap: 0.6rem;
  padding: 0.55rem 0;          /* touch-sized rows on phones */
  color: var(--text-3);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s;
}
/* Bracket box: "[ ]", which fills to "[-]" on hover or keyboard focus. */
.footer-nav .idx { color: var(--text-4); transition: color 0.15s; }
.footer-nav .fill::before { content: "-"; visibility: hidden; }
.footer-nav a:hover,
.footer-nav a:focus-visible,
.footer-nav a:hover .idx,
.footer-nav a:focus-visible .idx { color: var(--text); }
.footer-nav a:hover .fill::before,
.footer-nav a:focus-visible .fill::before { visibility: visible; }

.footer-controls { display: flex; }
.ctl {
  display: inline-grid;
  place-items: center;
  width: 2.75rem;              /* touch-sized on phones */
  height: 2.75rem;
  color: var(--text-3);
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.ctl + .ctl { margin-left: -1px; }
.ctl:hover { color: var(--text); border-color: var(--border-strong); position: relative; }
.ctl svg { width: 14px; height: 14px; }
.ctl [data-icon] { display: none; }
.ctl [data-icon].on { display: block; }
.ctl[hidden] { display: none; }

.colophon { display: flex; flex-direction: column; gap: 0.2rem; color: var(--text-3); font-size: 0.75rem; }
.colophon a { color: inherit; text-underline-offset: 3px; }
.colophon a:hover { color: var(--text); }

@media (min-width: 1024px) {
  .site-footer {
    grid-column: 1;
    grid-row: 1;
    align-self: end;
    margin: 0;
    padding: 4rem 1.5rem 1.5rem;
    border-top: 0;
    font-size: 0.8125rem;
  }
  .footer-nav a { padding: 0.2rem 0; }
  .ctl { width: 2rem; height: 2rem; }
}
/* Very short windows: let the nav scroll away rather than overlap
   the footer when both are on screen at the bottom of the page.
   In em (not px) so it also holds when visitors enlarge their
   default font size, which grows the nav and footer too. */
@media (min-width: 1024px) and (max-height: 40em) {
  .site-header { position: static; }
}

/* ---------- MARKDOWN ("bot") VIEW (site.js) ----------
   Replaces the page content with its generated index.md. */
.md-on main > :not(.md-view),
.md-on .toc { display: none !important; }
.md-view {
  max-width: var(--measure);
  margin: 0 var(--gutter);
  padding: 2.5rem 0 4rem;
  font-family: var(--font-mono);
}
.article-wrap > .md-view,
.writing-wrap > .md-view { margin: 0; padding-top: 0; }
@media (min-width: 1024px) {
  .md-view { margin-left: 0; padding-top: 4.5rem; }
}
.md-bar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-3);
}
.md-path { color: var(--text); overflow-wrap: anywhere; }
.md-actions { display: flex; gap: 1.25rem; flex-shrink: 0; }
.md-actions button {
  font: inherit;
  color: var(--text-3);
  background: none;
  border: 0;
  cursor: pointer;
  transition: color 0.15s;
}
.md-actions button:hover { color: var(--text); }
.md-src {
  font: inherit;
  font-size: 0.8125rem;
  line-height: 1.75;
  color: var(--text-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.md-src .md-mk { color: var(--text-4); }   /* decorative markers only */
.md-src .md-url { color: var(--text-3); }  /* link targets are readable text */
.md-src strong { color: var(--text); font-weight: 700; }
.md-src a { color: var(--text); text-underline-offset: 3px; }
/* Containers focused by script (so screen readers follow the view swap) don't need a ring. */
main:focus, .md-view:focus { outline: none; }
