/* ============================================================
   base.css — Reset, element defaults, global typography
   ============================================================ */

/* ── Box model ──────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

/* ── Root & body ────────────────────────────────────────────── */
html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  tab-size: 4;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  font-weight: var(--fw-regular);
  line-height: var(--lh-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
}

/* ── Headings ───────────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: var(--font-sans);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug);
  letter-spacing: var(--tracking-tight);
  color: var(--color-heading);
}

h1 { font-size: var(--fs-2xl); margin-bottom: var(--space-4); }
h2 { font-size: var(--fs-xl);  margin-bottom: var(--space-3); }
h3 { font-size: var(--fs-lg);  margin-bottom: var(--space-2); }
h4 { font-size: var(--fs-md);  margin-bottom: var(--space-2); }

/* ── Paragraphs & text ──────────────────────────────────────── */
p {
  line-height: var(--lh-normal);
  color: var(--color-text);
  max-width: var(--measure);
}
p + p { margin-top: var(--space-4); }

strong, b { font-weight: var(--fw-semibold); }
em, i     { font-style: italic; }
small     { font-size: var(--fs-sm); color: var(--color-text-muted); }

/* ── Links ──────────────────────────────────────────────────── */
a {
  color: var(--color-link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color var(--dur-fast) var(--ease-out);
}
a:hover  { color: var(--color-link-hover); }
a:visited { color: var(--color-link-visited); }

/* ── Focus ring (global) ────────────────────────────────────── */
:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--radius-sm);
}

/* ── :target highlight ──────────────────────────────────────── */
:target {
  scroll-margin-top: var(--space-7);
  background-color: var(--color-accent-soft);
  border-radius: var(--radius-sm);
  transition: background-color 0.6s var(--ease-out);
}

/* ── Lists ──────────────────────────────────────────────────── */
ul, ol {
  padding-left: var(--space-5);
}
ul { list-style: disc; }
ol { list-style: decimal; }
li { line-height: var(--lh-normal); }
li + li { margin-top: var(--space-1); }

/* ── Tables ─────────────────────────────────────────────────── */
table {
  border-collapse: collapse;
  width: 100%;
}
th, td {
  text-align: left;
  vertical-align: top;
  padding: var(--space-2) var(--space-3);
}
th {
  font-weight: var(--fw-semibold);
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  border-bottom: 2px solid var(--color-border-strong);
}
td {
  border-bottom: 1px solid var(--color-border);
  font-size: var(--fs-sm);
}

/* ── Visually hidden (screen-reader only) ───────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Horizontal rule ────────────────────────────────────────── */
hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-5) 0;
}

/* ── Code & pre ─────────────────────────────────────────────── */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-bg-sunken);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.35em;
  color: var(--color-text);
}
pre {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  background: var(--color-bg-sunken);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: var(--lh-normal);
}
pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* ── Images & media ─────────────────────────────────────────── */
img, video, svg {
  display: block;
  max-width: 100%;
}
figure { margin: var(--space-5) 0; }
figcaption {
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-2);
}

/* ── Fieldset ───────────────────────────────────────────────── */
fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}
legend {
  font-weight: var(--fw-semibold);
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  padding: 0 var(--space-2);
}

/* ── Details / summary defaults ─────────────────────────────── */
details summary {
  cursor: pointer;
  user-select: none;
}
details summary::-webkit-details-marker { display: none; }
details summary::marker { display: none; }

/* ── Selection ──────────────────────────────────────────────── */
::selection {
  background: var(--color-accent-soft);
  color: var(--color-heading);
}
