/* ==========================================================
   Raíces Ancestrales — hoja de estilos
   CSS moderno: capas, nesting nativo, oklch, clamp(),
   container queries, :has(), scroll-driven animations,
   view transitions. Sin frameworks.
   ========================================================== */

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

@layer reset {
  *, *::before, *::after { box-sizing: border-box; margin: 0; }
  html { -webkit-text-size-adjust: none; text-size-adjust: none; }
  img, svg, video { display: block; max-width: 100%; height: auto; }
  input, button, textarea, select { font: inherit; color: inherit; }
  :where(ul, ol)[role="list"] { list-style: none; padding: 0; }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  }
}

@layer tokens {
  :root {

    /* Paleta natural / ecológica */
    --bosque:   oklch(0.34 0.06 150);   /* #23412f verde bosque  */
    --musgo:    oklch(0.52 0.09 140);   /* #4f7a45 verde musgo   */
    --salvia:   oklch(0.78 0.05 135);   /* #b5c6a3 salvia        */
    --arcilla:  oklch(0.62 0.11 50);    /* #b9714a terracota     */
    --miel:     oklch(0.80 0.12 80);    /* #e0b25c miel / maíz   */
    --lino:     oklch(0.96 0.02 85);    /* #f6f0e4 papel / lino  */
    --tierra:   oklch(0.26 0.03 60);    /* #3a2e25 tierra oscura */

    /* Roles */
    --bg:        var(--lino);
    --bg-alt:    oklch(0.93 0.03 110);
    --surface:   oklch(0.99 0.01 85);
    --text:      var(--tierra);
    --text-soft: oklch(0.42 0.03 70);
    --primary:   var(--bosque);
    --accent:    var(--arcilla);
    --line:      oklch(0.85 0.03 90);

    /* Tipografía */
    --font-display: "Fraunces", "Georgia", serif;
    --font-body: "Nunito Sans", system-ui, sans-serif;
    --step--1: clamp(0.83rem, 0.8rem + 0.15vw, 0.93rem);
    --step-0:  clamp(1rem, 0.95rem + 0.25vw, 1.13rem);
    --step-1:  clamp(1.25rem, 1.15rem + 0.5vw, 1.5rem);
    --step-2:  clamp(1.56rem, 1.38rem + 0.9vw, 2.1rem);
    --step-3:  clamp(1.95rem, 1.6rem + 1.7vw, 3rem);
    --step-4:  clamp(2.4rem, 1.8rem + 3vw, 4.4rem);

    /* Espaciado y forma */
    --space-xs: 0.5rem; --space-s: 1rem; --space-m: 1.5rem;
    --space-l: clamp(2rem, 1.5rem + 2vw, 3rem);
    --space-xl: clamp(3.5rem, 2.5rem + 5vw, 7rem);
    --radius: 1.25rem;
    --radius-organic: 62% 38% 46% 54% / 48% 44% 56% 52%;
    --shadow: 0 1px 2px oklch(0.3 0.04 80 / .06), 0 12px 32px -12px oklch(0.3 0.04 80 / .25);
    --container: 72rem;
    --ease: cubic-bezier(.2,.7,.2,1);
  }

  /* Tema OSCURO (por defecto). Se activa con <html data-theme="dark">
     o cuando no hay data-theme. El claro usa los valores de arriba. */
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:        oklch(0.19 0.02 150);
    --bg-alt:    oklch(0.23 0.025 150);
    --surface:   oklch(0.26 0.028 150);
    --text:      oklch(0.93 0.02 90);
    --text-soft: oklch(0.78 0.03 100);
    --primary:   var(--salvia);
    --accent:    oklch(0.72 0.11 55);
    --line:      oklch(0.36 0.03 150);
    --shadow: 0 1px 2px oklch(0 0 0 / .3), 0 12px 32px -12px oklch(0 0 0 / .6);
    --footer-bg: oklch(0.15 0.02 150);
    --band-bg:   oklch(0.28 0.05 150);
  }
  :root[data-theme="light"] { color-scheme: light; --footer-bg: var(--tierra); --band-bg: var(--bosque); }
}

@layer base {
  html { scroll-behavior: smooth; scroll-padding-top: 5rem; }
  body {
    font-family: var(--font-body);
    font-size: var(--step-0);
    line-height: 1.65;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    overflow-x: clip;
  }
  h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-optical-sizing: auto;
    font-weight: 600;
    line-height: 1.1;
    color: var(--primary);
    text-wrap: balance;
    letter-spacing: -0.01em;
  }
  h1 { font-size: var(--step-4); }
  h2 { font-size: var(--step-3); }
  h3 { font-size: var(--step-1); }
  p { text-wrap: pretty; max-width: 65ch; }
  a { color: var(--accent); text-underline-offset: .2em; }
  :focus-visible { outline: 3px solid var(--miel); outline-offset: 3px; border-radius: 4px; }
  ::selection { background: var(--miel); color: var(--tierra); }

  @view-transition { navigation: auto; }
}

@layer layout {
  .container { width: min(100% - 2rem, var(--container)); margin-inline: auto; }
  .section { padding-block: var(--space-xl); }
  .section--alt { background: var(--bg-alt); }
  .stack > * + * { margin-top: var(--space-s); }
  .grid-auto { display: grid; gap: var(--space-m); grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); }
  .split { display: grid; gap: var(--space-l); align-items: center; }
  @media (min-width: 52rem) { .split { grid-template-columns: 1fr 1fr; } .split--reverse > :first-child { order: 2; } }
}

@layer components {
  /* ---------- Header ---------- */
  .site-header {
    position: sticky; top: 0; z-index: 50;
    background: color-mix(in oklch, var(--bg) 82%, transparent);
    backdrop-filter: blur(12px) saturate(1.2);
    border-bottom: 1px solid transparent;
    transition: border-color .3s;
    &.is-scrolled { border-color: var(--line); }

    .bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 4.5rem; }
  }
  .brand {
    display: inline-flex; align-items: center; gap: .6rem; text-decoration: none;
    font-family: var(--font-display); font-size: 1.3rem; font-weight: 600; color: var(--primary);
    img { width: 2.4rem; }
  }
  .nav {
    ul { display: flex; gap: clamp(.75rem, 2vw, 2rem); }
    a { color: var(--text); text-decoration: none; font-weight: 600; font-size: var(--step--1); letter-spacing: .02em; padding-block: .4rem; background: linear-gradient(var(--accent),var(--accent)) left bottom / 0 2px no-repeat; transition: background-size .3s var(--ease); }
    a:hover, a[aria-current="page"] { background-size: 100% 2px; }
  }
  .nav-toggle { display: none; background: none; border: 0; padding: .5rem; cursor: pointer; color: var(--primary); }
  .theme-toggle {
    background: var(--surface); border: 1px solid var(--line); border-radius: 99px; width: 2.4rem; height: 2.4rem;
    display: grid; place-items: center; cursor: pointer; color: var(--primary); transition: transform .3s var(--ease);
    &:hover { transform: rotate(20deg); }
    svg { grid-area: 1 / 1; }
    .icon-sun { display: none; }
  }
  /* En oscuro se muestra el sol (pasar a claro); en claro, la luna */
  :root:not([data-theme="light"]) .theme-toggle { .icon-sun { display: block; } .icon-moon { display: none; } }
  body { transition: background-color .3s, color .3s; }

  @media (max-width: 47.99rem) {
    .nav-toggle { display: block; }
    .nav {
      position: fixed; inset: 4.5rem 0 auto 0; background: var(--bg); border-bottom: 1px solid var(--line);
      padding: 1rem; translate: 0 -120%; transition: translate .35s var(--ease);
      ul { flex-direction: column; gap: .25rem; }
      a { display: block; padding: .75rem .5rem; font-size: var(--step-0); }
    }
    body:has(.nav-toggle[aria-expanded="true"]) .nav { translate: 0 0; }
  }

  /* ---------- Botones ---------- */
  .btn {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .9rem 1.6rem; border-radius: 99px; border: 2px solid var(--primary);
    background: var(--primary); color: var(--bg); font-weight: 700; text-decoration: none; cursor: pointer;
    transition: transform .2s var(--ease), background .2s, color .2s;
    &:hover { transform: translateY(-2px); background: var(--accent); border-color: var(--accent); color: #fff; }
    &.btn--ghost { background: transparent; color: var(--primary); }
    &.btn--ghost:hover { background: var(--primary); color: var(--bg); border-color: var(--primary); }
  }

  .eyebrow {
    display: inline-flex; align-items: center; gap: .5rem;
    font-size: var(--step--1); font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--accent);
    &::before { content: ""; width: 1.6rem; height: 2px; background: currentColor; }
  }
  .lead { font-size: var(--step-1); color: var(--text-soft); line-height: 1.5; }

  /* ---------- Hero ---------- */
  .hero {
    position: relative; padding-block: clamp(3rem, 8vw, 7rem) var(--space-xl); isolation: isolate;
    &::before { /* textura de papel orgánico */
      content: ""; position: absolute; inset: 0; z-index: -1; opacity: .5;
      background:
        radial-gradient(40rem 30rem at 85% 10%, color-mix(in oklch, var(--salvia) 55%, transparent), transparent 70%),
        radial-gradient(30rem 25rem at 0% 90%, color-mix(in oklch, var(--miel) 35%, transparent), transparent 70%);
    }
    .split { gap: var(--space-xl); }
    h1 em { font-style: italic; color: var(--accent); font-weight: 500; }
    .actions { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: var(--space-m); }
  }
  .hero-art {
    position: relative; aspect-ratio: 1; border-radius: var(--radius-organic); overflow: hidden; box-shadow: var(--shadow);
    animation: morph 14s ease-in-out infinite alternate;
    img { width: 100%; height: 100%; object-fit: cover; }
  }
  @keyframes morph {
    50% { border-radius: 42% 58% 60% 40% / 55% 38% 62% 45%; }
    100% { border-radius: 55% 45% 38% 62% / 40% 60% 40% 60%; }
  }

  .stats { display: flex; flex-wrap: wrap; gap: var(--space-l); margin-top: var(--space-l); padding-top: var(--space-m); border-top: 1px solid var(--line);
    strong { display: block; font-family: var(--font-display); font-size: var(--step-2); color: var(--primary); line-height: 1; }
    span { font-size: var(--step--1); color: var(--text-soft); }
  }

  /* ---------- Tarjetas de producto (container queries) ---------- */
  .product-card {
    container-type: inline-size;
    background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
    display: flex; flex-direction: column; text-decoration: none; color: inherit;
    transition: transform .35s var(--ease);
    &:hover { transform: translateY(-6px); }
    &:hover img { scale: 1.06; }
    figure { aspect-ratio: 4/3; overflow: hidden; background: var(--bg-alt); }
    img { width: 100%; height: 100%; object-fit: cover; transition: scale .6s var(--ease); }
    .body { padding: var(--space-m); display: grid; gap: .5rem; flex: 1; }
    .tag { font-size: .75rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--musgo); }
    .more { margin-top: auto; font-weight: 700; color: var(--accent); }
  }
  @container (min-width: 30rem) {
    .product-card .body { padding: var(--space-l); }
  }

  /* ---------- Proceso ---------- */
  .steps { counter-reset: paso; display: grid; gap: var(--space-m); grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); }
  .step {
    counter-increment: paso; position: relative; padding: var(--space-m); padding-top: 3.5rem;
    border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
    &::before {
      content: counter(paso, decimal-leading-zero); position: absolute; top: 1rem; left: var(--space-m);
      font-family: var(--font-display); font-size: 1.8rem; font-style: italic; color: var(--accent);
    }
  }

  /* ---------- Beneficios ---------- */
  .benefits { display: grid; gap: var(--space-s); grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); }
  .benefit {
    display: flex; gap: 1rem; align-items: flex-start; padding: var(--space-m); border-radius: var(--radius); background: var(--surface);
    .icon { flex: none; width: 3rem; height: 3rem; border-radius: 50%; display: grid; place-items: center; background: color-mix(in oklch, var(--salvia) 50%, transparent); color: var(--bosque); }
    h3 { font-size: 1.1rem; margin-bottom: .25rem; }
    p { font-size: var(--step--1); color: var(--text-soft); }
  }

  /* ---------- Ingredientes ---------- */
  .ingredients { display: flex; flex-wrap: wrap; gap: .6rem;
    li { padding: .5rem 1rem; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); font-weight: 600; font-size: var(--step--1); }
  }

  /* ---------- Galería ---------- */
  .gallery {
    display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr)); grid-auto-rows: 12rem;
    button { padding: 0; border: 0; border-radius: calc(var(--radius) * .7); overflow: hidden; cursor: zoom-in; background: var(--bg-alt); }
    button:first-child { grid-row: span 2; grid-column: span 2; }
    img { width: 100%; height: 100%; object-fit: cover; transition: scale .5s var(--ease); }
    button:hover img { scale: 1.05; }
  }
  @media (max-width: 30rem) { .gallery button:first-child { grid-column: span 1; } }

  .lightbox {
    border: 0; padding: 0; background: transparent; max-width: min(92vw, 60rem); max-height: 90vh;
    &::backdrop { background: oklch(0.15 0.02 150 / .85); backdrop-filter: blur(4px); }
    img { border-radius: var(--radius); max-height: 85vh; width: auto; margin: auto; }
    button { position: absolute; top: .5rem; right: .5rem; width: 2.5rem; height: 2.5rem; border-radius: 50%; border: 0; background: var(--lino); color: var(--tierra); font-size: 1.4rem; cursor: pointer; }
  }

  /* ---------- Cita / testimonio ---------- */
  .quote {
    text-align: center; max-width: 48rem; margin-inline: auto;
    blockquote { font-family: var(--font-display); font-size: var(--step-2); font-style: italic; line-height: 1.3; color: var(--primary); text-wrap: balance; }
    figcaption { margin-top: var(--space-s); color: var(--text-soft); font-weight: 600; }
  }

  /* ---------- Timeline (Sobre nosotros) ---------- */
  .timeline { border-left: 2px dashed var(--salvia); padding-left: var(--space-m); display: grid; gap: var(--space-l);
    li { position: relative; }
    li::before { content: ""; position: absolute; left: calc(-1 * var(--space-m) - 9px); top: .4rem; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--bg); }
    time { font-family: var(--font-display); font-size: var(--step-1); color: var(--accent); font-style: italic; }
  }

  /* ---------- Formulario ---------- */
  .form { display: grid; gap: var(--space-m); background: var(--surface); padding: var(--space-l); border-radius: var(--radius); box-shadow: var(--shadow);
    .row { display: grid; gap: var(--space-m); }
    @media (min-width: 40rem) { .row { grid-template-columns: 1fr 1fr; } }
    label { display: grid; gap: .4rem; font-weight: 700; font-size: var(--step--1); }
    input, textarea, select {
      width: 100%; padding: .85rem 1rem; border: 1.5px solid var(--line); border-radius: .75rem; background: var(--bg); font-weight: 400;
      transition: border-color .2s, box-shadow .2s;
      &:focus { outline: none; border-color: var(--musgo); box-shadow: 0 0 0 4px color-mix(in oklch, var(--musgo) 20%, transparent); }
      &:user-invalid { border-color: oklch(0.58 0.18 28); }
    }
    textarea { min-height: 9rem; resize: vertical; field-sizing: content; }
    .check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; input { width: auto; margin-top: .3rem; accent-color: var(--musgo); } }
    .status { font-weight: 700; color: var(--musgo); min-height: 1.5em; }
  }

  /* ---------- Page header (internas) ---------- */
  .page-hero { padding-block: var(--space-xl) var(--space-l); text-align: center;
    p { margin-inline: auto; }
    .breadcrumb { font-size: var(--step--1); color: var(--text-soft); margin-bottom: var(--space-s); a { color: inherit; } }
  }

  /* ---------- CTA band ---------- */
  .cta-band {
    background: var(--band-bg); color: var(--lino); border-radius: calc(var(--radius) * 1.5); padding: var(--space-l); text-align: center;
    background-image: radial-gradient(30rem 20rem at 100% 0%, oklch(0.52 0.09 140 / .6), transparent), radial-gradient(25rem 18rem at 0% 100%, oklch(0.62 0.11 50 / .35), transparent);
    h2 { color: var(--lino); }
    p { margin: var(--space-s) auto var(--space-m); opacity: .9; }
    .btn { background: var(--miel); border-color: var(--miel); color: var(--tierra); }
  }

  /* ---------- Footer ---------- */
  .site-footer {
    background: var(--footer-bg); color: oklch(0.88 0.02 85); padding-block: var(--space-xl) var(--space-m); margin-top: var(--space-xl);
    a { color: inherit; text-decoration: none; } a:hover { color: var(--miel); }
    .cols { display: grid; gap: var(--space-l); grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); }
    h4 { color: var(--miel); font-size: 1rem; margin-bottom: .75rem; font-family: var(--font-body); letter-spacing: .1em; text-transform: uppercase; }
    ul { display: grid; gap: .4rem; }
    .brand { color: var(--lino); }
    .legal { margin-top: var(--space-l); padding-top: var(--space-m); border-top: 1px solid oklch(1 0 0 / .12); font-size: var(--step--1); opacity: .75; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; }
  }

  /* ---------- Hoja divisoria orgánica ---------- */
  .divider { color: var(--bg-alt); display: block; width: 100%; height: clamp(2rem, 5vw, 4rem); margin-bottom: -1px; }

  /* ---------- Guía de estilo ---------- */
  .swatches { display: grid; gap: var(--space-s); grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
    li { border-radius: var(--radius); overflow: hidden; background: var(--surface); box-shadow: var(--shadow); }
    .chip { height: 6rem; }
    div:last-child { padding: .75rem 1rem; font-size: var(--step--1); }
    code { color: var(--text-soft); }
  }
}

@layer utilities {
  .visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .center { text-align: center; } .center p { margin-inline: auto; }
  .mt-l { margin-top: var(--space-l); }
  .skip-link { position: absolute; left: 1rem; top: -4rem; z-index: 100; background: var(--primary); color: var(--bg); padding: .6rem 1rem; border-radius: .5rem; &:focus { top: 1rem; } }

  /* Aparición al hacer scroll (scroll-driven, sin JS) */
  @supports (animation-timeline: view()) {
    .reveal { animation: reveal linear both; animation-timeline: view(); animation-range: entry 0% cover 30%; }
    @keyframes reveal { from { opacity: 0; translate: 0 2.5rem; } }
  }
}
