/* base.css — Reset, tipografía y layout responsivo (Tarea 5.2).
   Depende de las variables definidas en theme.css (NO se codifican
   colores que puentean el theming). Cubre:
   - Reset moderno y box model consistente
   - Tipografía fluida y legible
   - Layout responsivo (móvil / tablet / escritorio)
   - Foco visible con :focus-visible usando --color-focus (Req 16.2)
   - Contraste ≥ 4.5:1 heredado de las variables de theme.css (Req 16.3)
   - Utilidad .visually-hidden (etiqueta del selector de idioma)
   Requisitos: 4.1, 4.2, 4.3, 16.2, 16.3, 19.2, 19.3.
*/

/* ---------------------------------------------------------------------------
   1. Reset / normalización
--------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -moz-tab-size: 4;
  tab-size: 4;
  scroll-behavior: smooth;
}

body,
h1,
h2,
h3,
h4,
p,
figure,
blockquote,
dl,
dd,
ul,
ol {
  margin: 0;
}

ul,
ol {
  padding: 0;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Imágenes y medios adaptables por defecto. */
img,
picture,
svg,
canvas,
video {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Los controles de formulario heredan la tipografía. */
input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

/* Evita saltos de layout por listas de contenido muy largo. */
p,
h1,
h2,
h3,
h4 {
  overflow-wrap: break-word;
}

/* Barra de scroll acorde al tema (claro Chiikawa / oscuro Tokyo Night).
   Firefox usa scrollbar-color (pulgar / pista); WebKit/Chromium usan los
   pseudo-elementos ::-webkit-scrollbar. Ambos leen las variables del tema. */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-strong) transparent;
}

*::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background-color: var(--color-border-strong);
  border-radius: 999px;
  /* El borde transparente crea un margen que deja ver la pista bajo el pulgar. */
  border: 3px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-primary);
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

/* Respeta la preferencia de movimiento reducido. */
@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;
    scroll-behavior: auto !important;
  }
}

/* ---------------------------------------------------------------------------
   2. Tipografía
--------------------------------------------------------------------------- */
:root {
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";

  /* Escala tipográfica fluida (clamp: min, preferido, max). */
  --fs-300: 0.875rem;
  --fs-400: 1rem;
  --fs-500: clamp(1.0625rem, 0.98rem + 0.4vw, 1.25rem);
  --fs-600: clamp(1.25rem, 1.1rem + 0.75vw, 1.6rem);
  --fs-700: clamp(1.6rem, 1.3rem + 1.5vw, 2.25rem);
  --fs-800: clamp(2rem, 1.5rem + 2.5vw, 3rem);

  /* Espaciado y contenedor. */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;

  --container-max: 72rem; /* ~1152px escritorio */
  --container-pad: var(--space-4);
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-400);
  background-color: var(--color-bg);
  color: var(--color-text);
}

h1 {
  font-size: var(--fs-800);
  line-height: 1.15;
  font-weight: 700;
}

h2 {
  font-size: var(--fs-600);
  line-height: 1.25;
  font-weight: 700;
}

h3 {
  font-size: var(--fs-500);
  line-height: 1.3;
  font-weight: 600;
}

p {
  font-size: var(--fs-400);
}

a {
  color: var(--color-primary-hover);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

small,
.text-muted {
  color: var(--color-text-muted);
}

/* ---------------------------------------------------------------------------
   3. Layout responsivo
   Enfoque mobile-first: una sola columna por defecto; se amplía el ancho de
   contenedor y la densidad en tablet (≥ 600px) y escritorio (≥ 1024px).
   Todos los controles permanecen accesibles en cada breakpoint (Req 4.1–4.3).
--------------------------------------------------------------------------- */
body {
  display: flex;
  flex-direction: column;
}

main {
  flex: 1 1 auto;
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding: var(--space-5) var(--container-pad) var(--space-7);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

/* Contenedor horizontal reutilizable para header/footer. */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--container-pad);
}

/* Tablet. */
@media (min-width: 600px) {
  :root {
    --container-pad: var(--space-5);
  }

  main {
    padding-block: var(--space-6) var(--space-8);
    gap: var(--space-7);
  }
}

/* Escritorio. */
@media (min-width: 1024px) {
  :root {
    --container-pad: var(--space-6);
  }
}

/* ---------------------------------------------------------------------------
   4. Foco visible (Req 16.2)
   Indicador claro y consistente para todo elemento interactivo que recibe
   foco por teclado. Usa --color-focus definido en theme.css (claro y oscuro).
--------------------------------------------------------------------------- */
:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Elimina el outline por defecto sólo cuando NO es foco de teclado,
   preservando el anillo visible para usuarios de teclado. */
:focus:not(:focus-visible) {
  outline: none;
}

/* ---------------------------------------------------------------------------
   5. Utilidades
--------------------------------------------------------------------------- */

/* Oculta visualmente manteniendo el contenido accesible para lectores de
   pantalla (usado por la etiqueta del selector de idioma del header). */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Permite que un elemento oculto reaparezca al recibir foco (skip links). */
.visually-hidden:focus,
.visually-hidden:focus-within {
  position: static !important;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  clip-path: none;
  white-space: normal;
}
