:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #5b5b5b;
  --border: #e6e6e6;
  --link: #111111;

  /* Comfortable essay measure: ~65–75 characters per line */
  --measure: 72ch;
}

html {
  /* Fluid base size for readability across devices */
  font-size: clamp(17px, 1.2vw + 14px, 19px);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);

  /* Clean, modern essay default: high-quality system sans (fast, no external fonts). */
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica,
    Arial, "Apple Color Emoji", "Segoe UI Emoji";
  line-height: 1.75;

  font-weight: 400;
  letter-spacing: -0.005em;

  font-kerning: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

main {
  max-width: var(--measure);
  margin: clamp(2.5rem, 6vw, 4.5rem) auto;
  padding: 0 clamp(1rem, 4vw, 1.75rem);

  /* Auto-number diagrams within the main content */
  counter-reset: figure;
}

/* Typography rhythm */
p {
  margin: 0 0 1.1em;
}

/* Subtitle / deck under an H1 */
.deck {
  margin: 0.5rem 0 0.85rem;
  color: var(--muted);
  line-height: 1.4;
  font-size: 1.05rem;
}

/* Tags */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.4rem;
  margin-top: 0.35rem;
  padding: 0;
  font-size: 0.9rem;
  line-height: 1.2;
  color: var(--muted);
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.45rem;
  border: 1px solid color-mix(in oklab, var(--border) 75%, transparent);
  border-radius: 999px;
  background: color-mix(in oklab, var(--panel) 65%, transparent);
  color: inherit;
  white-space: nowrap;
}

/* Headings: crisp, modern, and clearly separated */
h1,
h2,
h3 {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica,
    Arial, "Apple Color Emoji", "Segoe UI Emoji";
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 2.25rem 0 0.75rem;
}

h1 {
  font-size: clamp(2rem, 3vw + 1rem, 2.6rem);
  margin-top: 0;
  letter-spacing: -0.01em;
}

/* Kicker line above an essay title (small, calm framing) */
.kicker {
  display: block;
  margin: 0 0 0.5rem;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica,
    Arial, "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Homepage name: quieter than the main heading */
.kicker--name {
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-transform: none;
  margin-bottom: 0.35rem;
}

h2 {
  font-size: clamp(1.35rem, 1.2vw + 1.05rem, 1.7rem);
}

h3 {
  font-size: 1.15rem;
}

/* Links: subtle, modern underline instead of border hacks */
a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--link), transparent 70%);
  text-underline-offset: 0.18em;
  text-decoration-thickness: 0.08em;
}

a:hover {
  text-decoration-color: color-mix(in srgb, var(--link), transparent 40%);
}

/* Lists */
ul,
ol {
  margin: 0 0 1.1em;
  padding-left: 1.25em;
}

li {
  margin: 0.35em 0;
}

/* Horizontal rule */
hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

/* Quotes */
blockquote {
  margin: 1.5rem 0;
  padding: 0.25rem 0 0.25rem 1rem;
  border-left: 3px solid var(--border);
  color: color-mix(in srgb, var(--fg), var(--muted) 35%);
}

/* Code (inline and blocks) */
code,
pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 0.95em;
}

code {
  background: color-mix(in srgb, var(--fg), transparent 96%);
  border: 1px solid color-mix(in srgb, var(--fg), transparent 92%);
  padding: 0.15em 0.35em;
  border-radius: 0.35rem;
}

pre {
  margin: 1.4rem 0;
  padding: 1rem;
  overflow: auto;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--fg), transparent 97%);
  line-height: 1.6;
}

pre code {
  background: transparent;
  border: 0;
  padding: 0;
}

/* Media: keep content within the measure */
img,
video {
  max-width: 100%;
  height: auto;
}

figure.diagram {
  counter-increment: figure;
  margin: 1.75rem 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: color-mix(in srgb, var(--fg), transparent 97%);
}

figure.diagram img {
  display: block;
  width: 100%;
  height: auto;
}

/* For tall/narrow diagrams, don't blow them up to the full text measure */
figure.diagram--narrow img {
  /* Keep these diagrams calm: cap width so Mermaid’s default 16px SVG text doesn’t feel oversized */
  width: min(100%, clamp(12rem, 42vw, 16.5rem));
  margin: 0 auto;
}

figure.diagram--narrow {
  padding: 0.85rem;
}

figure.diagram figcaption {
  margin-top: 0.75rem;
  font-size: 0.95rem;
  color: var(--muted);
  line-height: 1.5;
}

figure.diagram figcaption::before {
  content: "Figure " counter(figure) ": ";
  font-weight: 600;
  color: var(--fg);
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
