/* Base Styles - Reset and Typography
 * Source: Distill.pub + MDN typography guides
 * Uses CSS custom properties from variables.css
 */

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

/* Root font size */
html {
  font-size: var(--font-size-base, 18px);
  -webkit-text-size-adjust: 100%;
  background-color: var(--color-page-bg, var(--color-background, #ffffff));
}

/* Body defaults */
body {
  margin: 0;
  font-family: var(--font-body, sans-serif);
  font-size: 1rem;
  line-height: var(--line-height-body, 1.6);
  color: var(--color-text, rgba(0, 0, 0, 0.87));
}

/* Headings */
/* Sans-serif headings with 600 weight for clear hierarchy */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading, sans-serif);
  font-weight: 600;
  line-height: var(--line-height-heading, 1.3);
  margin-top: var(--spacing-xl, 2rem);
  margin-bottom: var(--spacing-md, 1rem);
  color: var(--color-text, rgba(0, 0, 0, 0.87));
}

h1 {
  font-size: var(--font-size-h1, 2.5rem);
  margin-top: 0;
}

h2 {
  font-size: var(--font-size-h2, 1.5rem);
}

h3 {
  font-size: var(--font-size-h3, 1.25rem);
}

h4 {
  font-size: var(--font-size-h4, 1.125rem);
}

h5 {
  font-size: var(--font-size-h5, 1rem);
}

h6 {
  font-size: var(--font-size-h6, 0.875rem);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Links */
a {
  color: var(--color-link, #0066cc);
  text-decoration: underline;
  text-decoration-color: var(--color-border, rgba(0, 0, 0, 0.1));
  text-underline-offset: 2px;
  transition: color var(--transition-fast, 150ms ease);
}

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

a:visited {
  color: var(--color-link-visited, #551a8b);
}

/* Paragraphs */
p {
  margin-top: 0;
  margin-bottom: var(--spacing-md, 1rem);
}

/* Lists */
ul, ol {
  padding-left: var(--spacing-lg, 1.5rem);
  margin-top: 0;
  margin-bottom: var(--spacing-md, 1rem);
}

li {
  margin-bottom: var(--spacing-xs, 0.25rem);
}

li > ul,
li > ol {
  margin-top: var(--spacing-xs, 0.25rem);
  margin-bottom: 0;
}

/* Inline code */
code {
  font-family: var(--font-mono, monospace);
  font-size: var(--font-size-small, 0.875rem);
  background: var(--color-background-code, rgba(0, 0, 0, 0.04));
  padding: 0.1em 0.3em;
  border-radius: var(--radius-sm, 3px);
}

/* Code blocks */
pre {
  font-family: var(--font-mono, monospace);
  font-size: var(--font-size-small, 0.875rem);
  background: var(--color-background-code, rgba(0, 0, 0, 0.04));
  padding: var(--spacing-md, 1rem);
  border-radius: var(--radius-md, 4px);
  overflow-x: auto;
  margin-top: 0;
  margin-bottom: var(--spacing-lg, 1.5rem);
  line-height: 1.5;
}

pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

/* Blockquotes */
blockquote {
  margin: 0 0 var(--spacing-md, 1rem) 0;
  padding-left: var(--spacing-lg, 1.5rem);
  border-left: 3px solid var(--color-border-strong, rgba(0, 0, 0, 0.2));
  color: var(--color-text-secondary, rgba(0, 0, 0, 0.6));
  font-style: italic;
}

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

/* Horizontal rules */
hr {
  border: none;
  border-top: 1px solid var(--color-border, rgba(0, 0, 0, 0.1));
  margin: var(--spacing-2xl, 3rem) 0;
}

/* Figures */
figure {
  margin-inline: 0;
  text-align: center;
}

/* Images */
img {
  max-width: 100%;
  height: auto;
  display: inline-block;
}

/* Figure images in dark mode: subtle background so black lines stay visible */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) figure img {
    background: rgba(255, 255, 255, 0.13);
    border-radius: 4px;
    padding: 0.5rem;
  }
}
[data-theme="dark"] figure img {
  background: rgba(255, 255, 255, 0.13);
  border-radius: 4px;
  padding: 0.5rem;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--spacing-lg, 1.5rem);
}

th, td {
  padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
  text-align: left;
  border-bottom: 1px solid var(--color-border, rgba(0, 0, 0, 0.1));
}

th {
  font-weight: 600;
  color: var(--color-text, rgba(0, 0, 0, 0.87));
}

/* Strong and emphasis */
strong, b {
  font-weight: 600;
}

em, i {
  font-style: italic;
}

/* Small text */
small {
  font-size: var(--font-size-small, 0.875rem);
  color: var(--color-text-secondary, rgba(0, 0, 0, 0.6));
}

/* Selection */
::selection {
  background: var(--color-selection);
}

/* Focus styles for accessibility */
:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--color-background);
}
