:root {
  /* Restrained, high-contrast palette (WCAG AAA compliant) */
  --color-bg: #f8faf9;
  --color-surface: #ffffff;
  --color-surface-subtle: #f0f4f2;
  --color-surface-code: #f3f6f4;
  --color-text-primary: #121816;
  --color-text-secondary: #3b4943;
  --color-text-muted: #53635c;
  --color-border: #d2ddd7;
  --color-border-subtle: #e5ece8;
  --color-accent: #0c5c36;
  --color-accent-hover: #074528;
  --color-accent-subtle: #eaf3ee;
  --color-focus-ring: #0c5c36;

  /* Zero-download system font stacks distinguishing I, l, and 1 */
  --font-sans: Verdana, Tahoma, "DejaVu Sans", "Noto Sans", sans-serif;
  --font-mono: Consolas, Menlo, "DejaVu Sans Mono", "Courier New", monospace;

  /* Restrained typography scale */
  --text-base: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
  --text-lead: clamp(1.0625rem, 1.02rem + 0.25vw, 1.1875rem);
  --text-sm: 0.875rem;

  --h1-size: clamp(1.85rem, 1.55rem + 1.5vw, 2.35rem);
  --h2-size: clamp(1.3rem, 1.15rem + 0.7vw, 1.6rem);
  --h3-size: clamp(1.12rem, 1.05rem + 0.35vw, 1.25rem);
  --h4-size: clamp(1rem, 0.96rem + 0.2vw, 1.1rem);

  --line-height-tight: 1.25;
  --line-height-heading: 1.35;
  --line-height-body: 1.7;

  /* Elevation & Shape */
  --radius-sm: 0.25rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;
  --shadow-sm: 0 1px 2px rgba(18, 24, 22, 0.05);
  --shadow-card: 0 1px 3px rgba(18, 24, 22, 0.07), 0 1px 2px rgba(18, 24, 22, 0.04);

  /* Layout & Spacing */
  --container-max-width: 48rem;
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 2.75rem;

  /* Accessibility Touch Target */
  --touch-target-min: 2.75rem;
  /* 44px minimum */
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0d1311;
    --color-surface: #141c19;
    --color-surface-subtle: #1c2723;
    --color-surface-code: #16211d;
    --color-text-primary: #f2f7f4;
    --color-text-secondary: #a7bbb2;
    --color-text-muted: #82978d;
    --color-border: #2b3d36;
    --color-border-subtle: #1e2c26;
    --color-accent: #34d399;
    --color-accent-hover: #5eead4;
    --color-accent-subtle: #132a21;
    --color-focus-ring: #34d399;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.2);
  }
}

/* ==========================================================================
   Base & Reset
   ========================================================================== */

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

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

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

/* Accessible Keyboard Focus */
:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

/* Reduced Motion Preference */
@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;
  }
}

/* ==========================================================================
   Header & Navigation
   ========================================================================== */

header {
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border-subtle);
  position: relative;
}

nav {
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding: var(--space-sm) var(--space-md);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
}

nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch-target-min);
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-decoration: none;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

nav a:first-child {
  font-weight: 700;
  color: var(--color-accent);
}

nav a:hover {
  color: var(--color-accent);
  background-color: var(--color-accent-subtle);
  border-color: var(--color-border-subtle);
}

/* ==========================================================================
   Main Content & Typography
   ========================================================================== */

main {
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding: var(--space-xl) var(--space-md) var(--space-2xl);
  overflow-wrap: break-word;
  word-wrap: break-word;
}

h1 {
  font-size: var(--h1-size);
  font-weight: 700;
  line-height: var(--line-height-tight);
  color: var(--color-text-primary);
  margin-top: 0;
  margin-bottom: var(--space-xs);
  letter-spacing: -0.015em;
}

/* Lead paragraph directly following main title */
h1+p {
  font-size: var(--text-lead);
  color: var(--color-text-secondary);
  margin-top: 0;
  margin-bottom: var(--space-2xl);
  line-height: 1.55;
}

h2 {
  font-size: var(--h2-size);
  font-weight: 700;
  line-height: var(--line-height-heading);
  color: var(--color-text-primary);
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-sm);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--color-border-subtle);
  letter-spacing: -0.01em;
}

h3 {
  font-size: var(--h3-size);
  font-weight: 600;
  line-height: var(--line-height-heading);
  color: var(--color-text-primary);
  margin-top: var(--space-xl);
  margin-bottom: var(--space-xs);
}

h4 {
  font-size: var(--h4-size);
  font-weight: 600;
  line-height: var(--line-height-heading);
  color: var(--color-text-secondary);
  margin-top: var(--space-lg);
  margin-bottom: var(--space-xs);
}

p {
  margin-top: 0;
  margin-bottom: var(--space-md);
  color: var(--color-text-secondary);
}

/* Content Links */
a {
  color: var(--color-accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

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

/* Dividers */
hr {
  border: 0;
  border-top: 1px solid var(--color-border-subtle);
  margin: var(--space-lg) 0;
}

/* ==========================================================================
   Code & Technical Commands
   ========================================================================== */

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 0.15em 0.35em;
  background-color: var(--color-surface-code);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  word-break: break-word;
}

pre {
  max-width: 100%;
  box-sizing: border-box;
  margin: var(--space-md) 0 var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-accent);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  line-height: 1.55;
  font-size: 0.875rem;
}

pre code {
  display: block;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  font-size: inherit;
  color: var(--color-text-primary);
  white-space: pre;
  word-break: normal;
}

/* ==========================================================================
   Footer
   ========================================================================== */

footer {
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding: 0 var(--space-md) var(--space-2xl);
}

footer hr {
  margin: 0 0 var(--space-md);
}

footer nav {
  padding: 0;
}

/* Responsive adjustments */
@media (min-width: 40rem) {
  header nav {
    padding: var(--space-sm) var(--space-lg);
  }

  main {
    padding: var(--space-2xl) var(--space-lg) calc(var(--space-2xl) * 1.5);
  }

  footer {
    padding: 0 var(--space-lg) var(--space-2xl);
  }
}