/* =========================================================
   Base Typography & Elements
   Consumes design tokens from tokens.css.
   ========================================================= */

html {
  box-sizing: border-box;
  font-size: 100%; /* baseline 16px for rem */
  scroll-behavior: smooth;
  scroll-padding-top: var(--space-8); /* keep anchors clear of the sticky header */
}

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

body {
  margin: 0;
  font-family: var(--font-serif);
  font-size: var(--fs-200);
  line-height: var(--leading-normal);
  letter-spacing: 0.003em;
  color: var(--color-text);
  text-rendering: optimizeLegibility;
}

/* =========================================================
   Headings
   ========================================================= */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: var(--leading-tight);
  letter-spacing: -0.01em;
  color: var(--color-heading);
  margin-top: var(--space-6);
  margin-bottom: var(--space-4);
  overflow-wrap: break-word;
  text-wrap: balance;
}

h1 { font-size: var(--fs-700); max-width: 17ch; }
h2 { font-size: var(--fs-600); max-width: 24ch; }
h3 { font-size: var(--fs-500); max-width: 32ch; }
h4 { font-size: var(--fs-400); }
h5 { font-size: var(--fs-300); }
h6 {
  font-size: var(--fs-300);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* =========================================================
   Text Elements
   ========================================================= */

p {
  max-width: var(--measure);
  margin: 0 0 var(--space-5);
  text-wrap: pretty;
  overflow-wrap: break-word;
}

.lead,
p.lead {
  font-size: var(--fs-300);
  font-family: var(--font-sans);
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--color-text-muted);
  line-height: 1.5;
}

small {
  font-size: var(--fs-100);
  color: var(--color-text-muted);
}

ul, ol {
  max-width: var(--measure);
  margin: 0 0 var(--space-5) var(--space-5);
  padding: 0;
}

li + li {
  margin-top: var(--space-1);
}

/* Links — clear affordance, animated underline, calm visited state */
a {
  color: var(--color-link);
  text-decoration-color: color-mix(in srgb, var(--color-link) 35%, transparent);
  text-underline-offset: 0.16em;
  transition: color var(--dur-fast) var(--ease-standard),
    text-decoration-color var(--dur-fast) var(--ease-standard);
}

a:visited {
  color: var(--color-link);
}

a:hover {
  color: var(--color-link-hover);
  text-decoration-color: currentColor;
}

h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
  text-decoration: none;
}

/* Blockquote — a designed pull-quote for long-form posts/chapters */
blockquote {
  max-width: var(--measure);
  margin: var(--space-6) 0;
  padding: var(--space-2) 0 var(--space-2) var(--space-5);
  border-left: 4px solid var(--color-accent);
  color: var(--color-text-muted);
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--fs-300);
  line-height: 1.45;
}

blockquote p:last-child {
  margin-bottom: 0;
}

/* Figures & captions */
figure {
  margin: var(--space-6) 0;
}

figcaption {
  margin-top: var(--space-2);
  font-family: var(--font-sans);
  font-size: var(--fs-100);
  color: var(--color-text-muted);
  text-align: center;
}

/* Horizontal rule — a subtle section divider */
hr {
  max-width: var(--measure);
  margin: var(--space-7) 0;
  border: 0;
  height: 1px;
  background: var(--color-border);
}

/* Inline SVG icons keep the text baseline tidy. */
.icon {
  display: inline-block;
  vertical-align: -0.125em;
  fill: currentColor;
}

code, pre {
  font-family: var(--font-mono);
  background: var(--color-code-bg);
  border-radius: var(--radius-sm);
}

code {
  padding: 0.1em 0.3em;
  font-size: 0.95em;
}

pre {
  max-width: var(--measure);
  padding: var(--space-4);
  overflow-x: auto;
  margin: 0 0 var(--space-5);
}

pre code {
  padding: 0;
  background: none;
}

/* =========================================================
   Form Elements
   ========================================================= */

input, button, textarea, select {
  font: inherit;
  font-family: var(--font-sans);
  color: inherit;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  background-color: var(--color-surface);
  transition: border-color var(--dur-fast) var(--ease-standard);
}

input:focus,
textarea:focus,
select:focus,
button:focus {
  outline: none;
  border-color: var(--color-focus);
}

button {
  cursor: pointer;
  background-color: var(--blue-500);
  color: #fff;
  border: none;
}

button:hover {
  background-color: var(--blue-600);
}

/* =========================================================
   Accessibility — visible focus, reduced motion
   ========================================================= */

:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* =========================================================
   Responsive Tweaks
   ========================================================= */

@media (max-width: 600px) {
  body { line-height: 1.6; }
}

@media (min-width: 1200px) {
  body { font-size: clamp(1rem, 0.9rem + 0.3vw, 1.125rem); }
}
