/**
 * base.css — tokens, reset y tipografía
 * La Choza de Migue v2
 */

@layer tokens, reset, base, layout, components, utilities;

/* ---------------------------------------------------------------- tokens */
@layer tokens {
  :root {
    /* Color: papel y tinta */
    --c-fondo:        #FAF7F0;
    --c-fondo-alt:    #F3EEE3;
    --c-superficie:   #FFFFFF;
    --c-tinta:        #1F1B16;
    --c-tinta-media:  #4A443C;
    --c-tinta-suave:  #6B6155;
    --c-tinta-tenue:  #9A9086;
    --c-linea:        #E3DACB;
    --c-linea-fuerte: #C4BAA9;

    /* Acentos */
    --c-acento:       #C1440E;
    --c-acento-osc:   #9A3608;
    --c-azulejo:      #2E5C6E;
    --c-olivo:        #5B7B3A;

    /* Categorías curadas */
    --cat-entrantes:  #C1440E;
    --cat-carnes:     #8C2F1B;
    --cat-verduras:   #5B7B3A;
    --cat-pescados:   #2E5C6E;
    --cat-sopas:      #A8752A;
    --cat-legumbres:  #7A5C2E;
    --cat-ensaladas:  #6B8E23;
    --cat-postres:    #B0447A;
    --cat-salsas:     #4A6B7A;
    --cat-conservas:  #6B6155;
    --cat-defecto:    #6B6155;

    /* Tipografía */
    --f-titular: 'Fraunces', 'Playfair Display', Georgia, 'Times New Roman', serif;
    --f-cuerpo:  'Source Serif 4', Georgia, 'Times New Roman', serif;
    --f-ui:      system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --f-mono:    ui-monospace, SFMono-Regular, Menlo, monospace;

    /* Escala tipográfica fluida */
    --t-xs:   0.75rem;
    --t-sm:   0.8125rem;
    --t-base: 0.9375rem;
    --t-md:   1rem;
    --t-lg:   clamp(1.0625rem, 0.4vw + 0.98rem, 1.1875rem);
    --t-xl:   clamp(1.1875rem, 0.6vw + 1.07rem, 1.375rem);
    --t-2xl:  clamp(1.375rem, 1vw + 1.18rem, 1.6875rem);
    --t-3xl:  clamp(1.625rem, 1.6vw + 1.32rem, 2.125rem);
    --t-4xl:  clamp(2rem, 2.6vw + 1.5rem, 3rem);
    --t-5xl:  clamp(2.375rem, 4.4vw + 1.5rem, 4.75rem);

    /* Espaciado */
    --e-1: 0.25rem;  --e-2: 0.5rem;   --e-3: 0.75rem;
    --e-4: 1rem;     --e-5: 1.5rem;   --e-6: 2rem;
    --e-7: 2.5rem;   --e-8: 3.5rem;   --e-9: 5rem;

    /* Medidas */
    --ancho-max:    1440px;
    --ancho-texto:  65ch;
    --margen-lat:   clamp(1.125rem, 4.4vw, 4rem);

    /* Otros */
    --borde: 1px solid var(--c-linea);
    --foco:  2px solid var(--c-acento);
    --trans: 160ms ease;
  }

  /* Modo oscuro: solo se redefinen tokens */
  @media (prefers-color-scheme: dark) {
    :root:not([data-tema="claro"]) {
      --c-fondo:        #16130F;
      --c-fondo-alt:    #1E1A15;
      --c-superficie:   #201C17;
      --c-tinta:        #F0E9DC;
      --c-tinta-media:  #D5CCBC;
      --c-tinta-suave:  #A79C8E;
      --c-tinta-tenue:  #7D7365;
      --c-linea:        #362F26;
      --c-linea-fuerte: #4A4136;
      --c-acento:       #E0662C;
      --c-acento-osc:   #F08447;
      --c-azulejo:      #6FA3B8;
      --c-olivo:        #8CAD62;
    }
  }

  :root[data-tema="oscuro"] {
    --c-fondo:        #16130F;
    --c-fondo-alt:    #1E1A15;
    --c-superficie:   #201C17;
    --c-tinta:        #F0E9DC;
    --c-tinta-media:  #D5CCBC;
    --c-tinta-suave:  #A79C8E;
    --c-tinta-tenue:  #7D7365;
    --c-linea:        #362F26;
    --c-linea-fuerte: #4A4136;
    --c-acento:       #E0662C;
    --c-acento-osc:   #F08447;
    --c-azulejo:      #6FA3B8;
    --c-olivo:        #8CAD62;
  }
}

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

  html {
    -webkit-text-size-adjust: 100%;
    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;
    }
  }

  html, body { max-width: 100%; }

  body {
    margin: 0;
    background: var(--c-fondo);
    color: var(--c-tinta);
    font-family: var(--f-cuerpo);
    font-size: var(--t-lg);
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
  }

  h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; }
  p, ul, ol, figure, blockquote, pre { margin: 0; }

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

  button, input, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; }

  :where(a) {
    color: var(--c-acento);
    text-decoration: none;
  }
  :where(a):hover { color: var(--c-acento-osc); }

  :focus-visible {
    outline: var(--foco);
    outline-offset: 2px;
  }
}

/* ------------------------------------------------------------------ base */
@layer base {
  .titular {
    font-family: var(--f-titular);
    font-weight: 600;
    line-height: 1.14;
    letter-spacing: -0.015em;
    text-wrap: balance;
  }

  /* Enlace de salto para lectores de pantalla */
  .saltar-a-contenido {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 999;
    background: var(--c-tinta);
    color: var(--c-fondo);
    padding: var(--e-3) var(--e-5);
  }
  .saltar-a-contenido:focus {
    left: var(--e-4);
    top: var(--e-4);
    color: var(--c-fondo);
  }

  .screen-reader-text {
    position: absolute !important;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }
}

/* ---------------------------------------------------------------- layout */
@layer layout {
  .contenedor {
    width: 100%;
    max-width: var(--ancho-max);
    margin-inline: auto;
    padding-inline: var(--margen-lat);
  }

  .seccion {
    padding-block: var(--e-8);
    border-bottom: var(--borde);
  }

  .seccion__cabecera {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--e-3);
    margin-bottom: var(--e-6);
  }

  .seccion__titulo { font-size: var(--t-3xl); }

  /* Cuadrículas responsivas sin media queries */
  .rejilla {
    display: grid;
    gap: var(--e-5);
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
  }

  .rejilla--recetas {
    gap: var(--e-6) var(--e-5);
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 17.5rem), 1fr));
  }

  .rejilla--dos {
    display: grid;
    gap: var(--e-6);
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
  }
}
