/*
 * r4ds.es — base styles
 * Reset, tipografía, layout primitivo.
 * Carga después de tokens.css.
 */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  hanging-punctuation: first last;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: var(--fs-base);
  font-weight: var(--fw-regular);
  font-feature-settings: 'ss01', 'cv11';
  line-height: 1.65;
  color: var(--color-text);
  background: var(--color-bg);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Display / Headings */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: var(--fw-medium);
  line-height: 1.15;
  letter-spacing: -0.015em;
  text-wrap: balance;
  margin: 0;
  color: var(--color-text);
}

h1 { font-size: var(--fs-4xl); letter-spacing: -0.025em; }
h2 { font-size: var(--fs-3xl); letter-spacing: -0.02em; }
h3 { font-size: var(--fs-2xl); }
h4 { font-size: var(--fs-xl); }
h5 { font-size: var(--fs-lg); }
h6 { font-size: var(--fs-base); }

p, ul, ol, dl, blockquote, figure, pre, table {
  margin: 0 0 1em;
}

p, li { text-wrap: pretty; }

ul, ol { padding-left: 1.25em; }

a {
  color: var(--color-link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: color-mix(in srgb, var(--color-link) 40%, transparent);
  transition: color var(--t-fast) var(--ease-out), text-decoration-color var(--t-fast);
}
a:hover { color: var(--color-link-hover); text-decoration-color: currentColor; }

strong, b { font-weight: var(--fw-bold); }
em, i { font-style: italic; }

code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 0.92em;
  font-feature-settings: 'liga' 0;
}
code:not(pre code) {
  background: var(--color-bg-sunken);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-soft);
}
pre {
  background: var(--color-bg-sunken);
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  overflow-x: auto;
  line-height: 1.55;
}

blockquote {
  margin-inline: 0;
  padding: 0.5rem 0 0.5rem 1.25rem;
  border-left: 3px solid var(--brand-400);
  color: var(--color-text-muted);
  font-style: italic;
}

hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 2rem 0;
}

img, svg, video, picture { max-width: 100%; height: auto; display: block; }

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
th, td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
}
th { font-weight: var(--fw-medium); color: var(--color-text-muted); font-size: var(--fs-sm); }

/* Focus universal */
:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Selección */
::selection {
  background: var(--brand-200);
  color: var(--brand-900);
}

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--brand-900);
  color: var(--ink-50);
  padding: 0.6rem 1rem;
  border-radius: 0 0 var(--radius) 0;
  z-index: var(--z-nav);
}
.skip-link:focus-visible { left: 0; }

/* Layout helpers */
.container {
  width: min(var(--content-width), 100% - 2 * var(--gutter));
  margin-inline: auto;
}
.container--narrow {
  width: min(var(--content-narrow), 100% - 2 * var(--gutter));
  margin-inline: auto;
}

.stack > * + * { margin-top: 1em; }
.stack-lg > * + * { margin-top: 1.5em; }
.stack-xl > * + * { margin-top: 2.5em; }

.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;
}

/* Tipografía utilitaria */
.text-muted { color: var(--color-text-muted); }
.text-soft  { color: var(--color-text-soft); }
.text-sm    { font-size: var(--fs-sm); }
.text-xs    { font-size: var(--fs-xs); }
.tabular    { font-variant-numeric: tabular-nums; }
.mono       { font-family: var(--font-mono); }
