/* Design tokens: the frequent-edit file. A look change is usually a token edit,
   not a hunt through components (docs/presentation.md). Rebrand by changing values
   here. Light is the default on :root; dark is applied by the toggle
   ([data-theme="dark"]) and by the system preference when the reader has not chosen. */

:root {
  /* Neutral palette (light) */
  --bg: #fbfbf9;
  --surface: #ffffff;
  --fg: #1c1c1a;
  --muted: #6b6b64;
  --border: #e5e4de;
  --accent: #3a6ea5;
  --accent-fg: #ffffff;
  --code-bg: #f4f3ee;
  --code-fg: #23231f;
  --callout-bg: #f4f3ee;
  --selection: #dfe8f2;

  /* Typography */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --text-base: 1.125rem;
  --text-sm: 0.9rem;
  --text-lg: 1.35rem;
  --h1: 2.3rem;
  --h2: 1.7rem;
  --h3: 1.35rem;
  --h4: 1.12rem;
  --line: 1.7;

  /* Space and shape */
  --measure: 42rem;
  --wrap: 46rem;
  --space-1: 0.35rem;
  --space-2: 0.7rem;
  --space-3: 1.1rem;
  --space-4: 1.8rem;
  --space-5: 3rem;
  --radius: 8px;
  --radius-sm: 5px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181a;
    --surface: #1f2023;
    --fg: #e7e6e1;
    --muted: #a2a29a;
    --border: #33343a;
    --accent: #8bb4e0;
    --accent-fg: #16171a;
    --code-bg: #24262b;
    --code-fg: #e7e6e1;
    --callout-bg: #23252a;
    --selection: #2c3a4d;
  }
}

:root[data-theme="dark"] {
  --bg: #17181a;
  --surface: #1f2023;
  --fg: #e7e6e1;
  --muted: #a2a29a;
  --border: #33343a;
  --accent: #8bb4e0;
  --accent-fg: #16171a;
  --code-bg: #24262b;
  --code-fg: #e7e6e1;
  --callout-bg: #23252a;
  --selection: #2c3a4d;
}

/* Resets and element defaults. */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--line);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--selection); }

h1, h2, h3, h4 {
  font-family: var(--font-sans);
  line-height: 1.25;
  font-weight: 650;
  margin: var(--space-4) 0 var(--space-2);
}
h1 { font-size: var(--h1); letter-spacing: -0.02em; }
h2 { font-size: var(--h2); letter-spacing: -0.01em; }
h3 { font-size: var(--h3); }
h4 { font-size: var(--h4); }

p { margin: 0 0 var(--space-3); }

a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

strong { font-weight: 650; }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-5) 0;
}

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

code, pre { font-family: var(--font-mono); }

:not(pre) > code {
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 0.12em 0.36em;
  border-radius: var(--radius-sm);
  font-size: 0.88em;
}

ul, ol { margin: 0 0 var(--space-3); padding-left: 1.4em; }
li { margin: var(--space-1) 0; }

blockquote {
  margin: var(--space-4) 0;
  padding: var(--space-1) var(--space-3);
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
blockquote p:last-child { margin-bottom: 0; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-fg);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
}
.skip-link:focus { left: var(--space-2); top: var(--space-2); z-index: 10; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Page structure. */

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: var(--space-3);
}

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

.site-main { flex: 1 0 auto; padding-block: var(--space-5); }

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: var(--space-3);
}
.site-name {
  font-weight: 650;
  font-size: var(--text-lg);
  color: var(--fg);
  text-decoration: none;
}

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: var(--text-sm);
  padding-block: var(--space-4);
}

/* The reading column for article bodies. */
.post-body, .page-body { max-width: var(--measure); }
.post-body { font-family: var(--font-serif); }

/* Callouts. */

.callout {
  display: flex;
  gap: var(--space-3);
  background: var(--callout-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin: var(--space-4) 0;
}
.callout-icon { flex: 0 0 auto; font-size: 1.2rem; line-height: 1.5; }
.callout-icon img { width: 1.3rem; height: 1.3rem; }
.callout-body > :first-child { margin-top: 0; }
.callout-body > :last-child { margin-bottom: 0; }

/* Code blocks. */

pre {
  background: var(--code-bg);
  color: var(--code-fg);
  padding: var(--space-3);
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.5;
  margin: var(--space-4) 0;
}
pre code { background: none; padding: 0; font-size: inherit; }

figure.code { margin: var(--space-4) 0; }
figure.code pre { margin: 0; }
figure.code figcaption {
  color: var(--muted);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
}

/* Embeds: framed third-party content (maps, video), kept responsive. */

figure.embed {
  margin: var(--space-4) 0;
}
.embed__frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.embed__frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
figure.embed figcaption {
  color: var(--muted);
  font-size: var(--text-sm);
  text-align: center;
  margin-top: var(--space-2);
}

/* Figures and images. */

figure.image {
  margin: var(--space-4) 0;
}
figure.image img {
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
figure.image figcaption {
  color: var(--muted);
  font-size: var(--text-sm);
  text-align: center;
  margin-top: var(--space-2);
}

/* Site header: the theme toggle and its icons. */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--accent); }

/* Show the icon for the theme the toggle switches to. */
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }

:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* To-do lists and toggles. */

.todo-list { list-style: none; padding-left: 0; }
.todo-item { display: block; }
.todo-item label { display: inline-flex; align-items: baseline; gap: var(--space-2); }
.todo-item input { margin-top: 0.35em; }
.todo-item.done > label { color: var(--muted); text-decoration: line-through; }

details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  margin: var(--space-3) 0;
  background: var(--surface);
}
details > summary {
  cursor: pointer;
  font-weight: 600;
}
details[open] > summary { margin-bottom: var(--space-2); }
.toggle-body > :last-child { margin-bottom: 0; }

/* Math. Block equations scroll horizontally if they overflow. */

.math-block {
  margin: var(--space-4) 0;
  overflow-x: auto;
  text-align: center;
}
.math-inline { white-space: nowrap; }

/* Native MathML sizing. Block equations render a touch larger and centered. */
.math math { font-size: 1.05em; }
.math-block math { display: block; margin: 0 auto; }

/* Tables. Wide tables scroll inside their own container. */

.table-wrap { overflow-x: auto; margin: var(--space-4) 0; }

table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--text-sm);
}
th, td {
  border: 1px solid var(--border);
  padding: var(--space-2) var(--space-3);
  text-align: left;
  vertical-align: top;
}
thead th { background: var(--code-bg); font-weight: 650; }

/* Home and tag listing pages. */

.listing-heading { margin-top: 0; margin-bottom: var(--space-4); }

.card-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-5); }

.card-title { margin: 0 0 var(--space-1); font-size: var(--text-lg); }
.card-title a { color: var(--fg); text-decoration: none; }
.card-title a:hover { text-decoration: underline; }

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  color: var(--muted);
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}
.card-meta time { white-space: nowrap; }
.card-meta .tag a { color: inherit; text-decoration: none; }
.card-meta .tag a:hover { text-decoration: underline; }

.card-summary { margin: 0; max-width: var(--measure); color: var(--fg); }

.listing-empty { color: var(--muted); }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  font-size: var(--text-sm);
}
.page-link { color: var(--fg); text-decoration: none; }
.page-link:hover { text-decoration: underline; }
.page-of { color: var(--muted); }

/* Post and standalone-page headers. */

.post-header, .page-header { margin-bottom: var(--space-4); }
.post-header h1, .page-header h1 { margin-top: 0; }

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  color: var(--muted);
  font-size: var(--text-sm);
}
.post-meta time { white-space: nowrap; }

.tags { display: flex; flex-wrap: wrap; gap: var(--space-1); list-style: none; margin: 0; padding: 0; }
.tag {
  background: var(--code-bg);
  border-radius: 999px;
  padding: 0.1em 0.7em;
  font-size: var(--text-sm);
}

.post-body > :first-child, .page-body > :first-child { margin-top: 0; }

/* Inline text colors from CMS annotations. */
.rt-color-gray { color: var(--muted); }
