/* ==========================================================================
   Círculo Masajistas Referentes · Landing
   CSS moderno sin preprocesadores: @layer, nesting, container queries,
   color-mix(), clamp(), scroll-driven animations (con fallback en JS).
   ========================================================================== */

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

/* ---------- RESET ---------- */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; scroll-padding-top: 5rem; }
  img { display: block; max-width: 100%; height: auto; }
  a { color: inherit; }
  ul, ol { padding: 0; list-style: none; }
  button { font: inherit; color: inherit; }
}

/* ---------- BASE: tokens y tipografía ---------- */
@layer base {
  :root {
    color-scheme: dark;

    /* Paleta (oscura por defecto) */
    --bg: #0b0b0d;
    --bg-2: #121216;
    --surface: #18181d;
    --text: #f4f1ea;
    --muted: #b0ab9f;
    --accent: #e8b84f;
    --accent-2: #f6d27a;
    --btn-a: #f6d27a;
    --btn-b: #e0a93a;
    --btn-ink: #1a1300;
    --wa: #25d366;
    --wa-ink: #052e16;
    --bad: #ff7a6b;
    --line: color-mix(in srgb, var(--text) 13%, transparent);
    --glow: color-mix(in srgb, var(--accent) 22%, transparent);

    /* Tipografía del sistema: cero fuentes externas */
    --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-display: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;

    /* Escala fluida */
    --step-0: clamp(1rem, 0.96rem + 0.2vw, 1.125rem);
    --step-1: clamp(1.15rem, 1.08rem + 0.4vw, 1.4rem);
    --step-2: clamp(1.4rem, 1.2rem + 1vw, 2rem);
    --step-3: clamp(1.75rem, 1.35rem + 2vw, 3rem);
    --step-4: clamp(2rem, 1.45rem + 2.4vw, 3.3rem);

    --section: clamp(3.5rem, 2.4rem + 5vw, 6.5rem);
    --radius: 1.1rem;
    --wrap: 72rem;
    --bar-h: 4.5rem;
  }

  @media (prefers-color-scheme: light) {
    :root {
      color-scheme: light;
      --bg: #faf7f0;
      --bg-2: #f1ece0;
      --surface: #ffffff;
      --text: #17140d;
      --muted: #5a5446;
      --accent: #8a5a00;
      --accent-2: #a66e00;
      --bad: #b3261e;
      --glow: color-mix(in srgb, #e0a93a 30%, transparent);
    }
  }

  @media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
  }

  body {
    background: var(--bg);
    color: var(--text);
    font: var(--step-0) / 1.65 var(--font-body);
    overflow-x: clip;
    -webkit-font-smoothing: antialiased;
  }

  h1, h2, h3 { font-family: var(--font-display); line-height: 1.12; text-wrap: balance; }
  h1 { font-size: var(--step-4); letter-spacing: -0.02em; }
  h2 { font-size: var(--step-3); letter-spacing: -0.015em; }
  h3 { font-size: var(--step-1); }
  p { text-wrap: pretty; }
  em { font-style: normal; color: var(--accent); }
  strong { font-weight: 700; }

  :focus-visible { outline: 3px solid var(--accent-2); outline-offset: 3px; border-radius: 4px; }
}

/* ---------- LAYOUT ---------- */
@layer layout {
  .wrap { width: min(100% - 2.5rem, var(--wrap)); margin-inline: auto; }
  .wrap--narrow { width: min(100% - 2.5rem, 48rem); }

  .section { padding-block: var(--section); }
  .section--alt { background: var(--bg-2); }

  .sec-head {
    max-width: 46rem;
    margin-bottom: clamp(1.75rem, 1rem + 3vw, 3rem);
    display: grid;
    gap: 0.9rem;
    .sub { color: var(--muted); font-size: var(--step-1); }
  }

  .eyebrow {
    font: 700 0.78rem / 1.2 var(--font-body);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--accent);
  }

  /* HERO */
  .hero {
    padding-block: clamp(1.75rem, 1rem + 3vw, 3.5rem) var(--section);
    background:
      radial-gradient(55rem 28rem at 85% -10%, var(--glow), transparent 65%),
      radial-gradient(40rem 24rem at -10% 25%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 65%);
  }
  .hero__grid { display: grid; gap: 2.5rem; align-items: center; }
  @media (min-width: 60rem) {
    .hero__grid { grid-template-columns: 1.2fr 0.8fr; gap: 4rem; }
  }
  .hero__text { display: grid; gap: 1.15rem; justify-items: start; }
  .lead { font-size: clamp(1.02rem, 0.98rem + 0.3vw, 1.2rem); color: var(--muted); max-width: 38rem; strong { color: var(--text); } }
  .hero__cta { display: grid; gap: 0.7rem; justify-items: start; }
  .micro { font-size: 0.85rem; color: var(--muted); }

  .hero__photo {
    position: relative;
    width: min(100%, 24rem);
    margin-inline: auto;
    aspect-ratio: 4 / 5;
    border-radius: calc(var(--radius) * 1.6);
    box-shadow: 0 2.5rem 5rem -2rem var(--glow), 0 0 0 1px var(--line);
    img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
  }

  /* Banda de cifras */
  .band { border-block: 1px solid var(--line); background: var(--bg-2); padding-block: clamp(1.75rem, 1rem + 3vw, 3rem); }
  .band__grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.75rem 1rem; text-align: center; }
  @media (min-width: 48rem) { .band__grid { grid-template-columns: repeat(4, 1fr); } }

  /* Jordi */
  .jordi { display: grid; gap: 2.5rem; align-items: center; }
  @media (min-width: 56rem) { .jordi { grid-template-columns: 0.8fr 1.2fr; gap: 4rem; } }
  .jordi__photo { width: min(100%, 24rem); margin-inline: auto; aspect-ratio: 4 / 5; border-radius: calc(var(--radius) * 1.6); overflow: hidden; box-shadow: 0 0 0 1px var(--line); img { width: 100%; height: 100%; object-fit: cover; } }
  .jordi__text { display: grid; gap: 1.25rem; justify-items: start; }

  /* Pilares: container query en lugar de media query */
  .pillars { container-type: inline-size; }
  .pillars__grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
  @container (min-width: 34rem) { .pillars__grid { grid-template-columns: repeat(2, 1fr); } }
  @container (min-width: 62rem) { .pillars__grid { grid-template-columns: repeat(4, 1fr); } }

  /* Grids de tarjetas */
  .cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); }

  /* Historia, fotos de prueba y capturas del aula */
  .story { margin-top: var(--section); }
  .timeline { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); }
  .proof { display: grid; gap: 1rem; margin-top: clamp(1.75rem, 1rem + 3vw, 3rem); }
  @media (min-width: 48rem) { .proof { grid-template-columns: 0.8fr 1.2fr; align-items: stretch; } }
  .shots { display: grid; gap: 1.25rem; margin-top: clamp(1.75rem, 1rem + 3vw, 3rem); }
  @media (min-width: 56rem) { .shots { grid-template-columns: repeat(3, 1fr); } }

  .fit { display: grid; gap: 1rem; }
  @media (min-width: 48rem) { .fit { grid-template-columns: 1fr 1fr; gap: 1.5rem; } }

  .steps { display: grid; gap: 1rem; counter-reset: s; }
  @media (min-width: 48rem) { .steps { grid-template-columns: repeat(3, 1fr); gap: 1.5rem; } }
}

/* ---------- COMPONENTES ---------- */
@layer components {
  .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .icon { width: 1.25em; height: 1.25em; flex: none; }

  .skip {
    position: fixed; left: 1rem; top: -4rem; z-index: 100;
    background: var(--accent); color: var(--btn-ink); padding: 0.7rem 1rem; border-radius: 0.5rem; font-weight: 700;
    &:focus { top: 1rem; }
  }

  /* Botones */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.6rem;
    min-height: 3rem; padding: 0.85em 1.5em;
    border-radius: 999px; border: 0;
    font-weight: 700; line-height: 1.2; text-align: center; text-decoration: none;
    color: var(--btn-ink);
    background: linear-gradient(135deg, var(--btn-a), var(--btn-b));
    box-shadow: 0 0.6rem 1.6rem -0.6rem color-mix(in srgb, var(--btn-b) 70%, transparent);
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
    &:hover { transform: translateY(-2px); filter: brightness(1.06); box-shadow: 0 0.9rem 2rem -0.6rem color-mix(in srgb, var(--btn-b) 80%, transparent); }
    &:active { transform: translateY(0); }
  }
  .btn--lg { font-size: var(--step-1); padding: 1em 1.7em; }
  .btn--sm { min-height: 2.5rem; padding: 0.5em 1.1em; font-size: 0.9rem; }

  /* Barra superior */
  .topbar {
    position: sticky; top: 0; z-index: 50;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
  }
  .topbar__in { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; min-height: 3.75rem; padding-block: 0.4rem; }
  .brand { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.04em; line-height: 1.25; span { color: var(--accent); } }
  @media (min-width: 40rem) { .brand { font-size: 0.9rem; } }

  /* Chips y badges */
  .chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
  .chips li {
    padding: 0.4em 0.9em; border: 1px solid var(--line); border-radius: 999px;
    font-size: 0.88rem; font-weight: 600;
    background: color-mix(in srgb, var(--accent) 10%, transparent);
  }
  .badge {
    position: absolute; display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.55em 1em; border-radius: 999px; font-size: 0.85rem; font-weight: 700;
    background: color-mix(in srgb, #0b0b0d 82%, transparent); color: #f4f1ea;
    backdrop-filter: blur(8px); border: 1px solid rgb(255 255 255 / 0.16);
    .icon { color: #f6d27a; width: 1em; height: 1em; }
  }
  .badge--rating { left: -0.5rem; bottom: 2rem; }
  .badge--members { right: -0.5rem; top: 2rem; }

  /* Cifras */
  .stat__n { font: 700 var(--step-3) / 1.1 var(--font-display); color: var(--accent); font-variant-numeric: tabular-nums; }
  .stat__l { margin-top: 0.3rem; font-size: 0.9rem; color: var(--muted); }

  /* Tira de CTA */
  .cta-strip {
    margin-top: clamp(2rem, 1rem + 4vw, 3.5rem);
    padding: clamp(1.1rem, 1rem + 1vw, 1.6rem);
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem 1.5rem;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: linear-gradient(120deg, color-mix(in srgb, var(--accent) 12%, var(--surface)), var(--surface));
    p { font-family: var(--font-display); font-size: var(--step-1); line-height: 1.25; flex: 1 1 18rem; }
  }
  /* Primera tira bajo la banda: sin margen superior excesivo */
  .band + .wrap .cta-strip { margin-top: clamp(1.75rem, 1rem + 3vw, 3rem); }

  /* Tarjetas */
  .card {
    padding: 1.4rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
    display: grid; gap: 0.6rem; align-content: start;
    transition: border-color 0.25s ease, transform 0.25s ease;
    &:hover { border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
    p { color: var(--muted); }
  }
  .cards--pain .card { grid-template-columns: auto 1fr; align-items: start; gap: 0.9rem; p { color: var(--text); } }
  .icon--bad { color: var(--bad); margin-top: 0.2rem; }
  .icon--ok { color: var(--accent); }
  .cards--benefit .card .icon { width: 1.6rem; height: 1.6rem; padding: 0.3rem; border-radius: 50%; background: color-mix(in srgb, var(--accent) 16%, transparent); }

  .card--pillar, .timeline .card { padding: 1.6rem; .num { font: 700 2.6rem / 1 var(--font-display); color: var(--accent); opacity: 0.9; } }
  .modules .card h3 { font-size: 1.1rem; }

  /* Fotos con pie */
  .proof figure, .shots figure {
    position: relative; overflow: hidden; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
    img { width: 100%; height: 100%; object-fit: cover; }
    figcaption { padding: 0.7rem 1rem; font-size: 0.85rem; color: var(--muted); }
  }
  .proof figure { display: grid; grid-template-rows: 1fr auto; }
  .shots figure { display: grid; grid-template-rows: auto auto; img { height: auto; } }

  .punch {
    margin-block: clamp(2rem, 1rem + 4vw, 3.5rem) 0;
    font: 700 var(--step-3) / 1.15 var(--font-display); text-align: center; text-wrap: balance;
  }
  .goal {
    margin-top: clamp(1.75rem, 1rem + 3vw, 3rem);
    padding: clamp(1.25rem, 1rem + 1.5vw, 2rem);
    font-size: var(--step-1); text-align: center; text-wrap: balance;
    border-block: 1px solid var(--line);
    strong { color: var(--accent); }
  }

  /* Jordi */
  .prose { display: grid; gap: 1rem; color: var(--muted); strong { color: var(--text); } q { color: var(--text); font-style: italic; } }
  .logos { display: flex; flex-wrap: wrap; gap: 0.5rem; li { padding: 0.35em 0.85em; border: 1px solid var(--line); border-radius: 0.5rem; font-size: 0.82rem; font-weight: 600; color: var(--muted); } }

  /* Carrusel de testimonios (scroll-snap puro; JS solo añade botones) */
  .rating { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; color: var(--muted); .stars { display: inline-flex; color: var(--accent); } strong { color: var(--text); } }
  .carousel {
    display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 1rem;
    scroll-snap-type: x mandatory; overscroll-behavior-x: contain; scrollbar-width: thin;
  }
  .quote {
    flex: 0 0 min(86%, 26rem); scroll-snap-align: start;
    display: grid; gap: 1rem; align-content: space-between;
    padding: 1.6rem; min-height: 12rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
    blockquote { font-family: var(--font-display); font-size: 1.1rem; line-height: 1.45; }
    .quote__by { color: var(--accent); font-weight: 700; font-size: 0.9rem; }
  }
  .carousel-nav {
    display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem;
    button {
      width: 2.75rem; height: 2.75rem; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
      border: 1px solid var(--line); background: var(--surface);
      &:hover { border-color: var(--accent); }
      .icon { width: 1.2rem; height: 1.2rem; }
      &:first-child .icon { rotate: 180deg; }
    }
  }

  /* Para quién es */
  .fit__col {
    padding: clamp(1.25rem, 1rem + 1.5vw, 2rem); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
    display: grid; gap: 1.1rem; align-content: start;
    ul { display: grid; gap: 0.8rem; }
    li { display: grid; grid-template-columns: auto 1fr; gap: 0.7rem; align-items: start; .icon { margin-top: 0.25rem; } }
  }
  .fit__col--yes { border-color: color-mix(in srgb, var(--accent) 50%, transparent); }

  /* Pasos */
  .step {
    counter-increment: s;
    position: relative; padding: 1.6rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
    display: grid; gap: 0.6rem;
    p { color: var(--muted); }
  }
  .step__n {
    width: 2.6rem; height: 2.6rem; border-radius: 50%; display: grid; place-items: center;
    font: 700 1.3rem var(--font-display); color: var(--btn-ink);
    background: linear-gradient(135deg, var(--btn-a), var(--btn-b));
  }

  /* Colaboración */
  .collab {
    text-align: center; display: grid; gap: 1rem; justify-items: center; max-width: 46rem;
    h2 span { color: var(--accent); }
    p:last-child { color: var(--muted); }
  }

  /* FAQ */
  .faq { display: grid; gap: 0.75rem; }
  .faq details {
    border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
    &[open] { border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
    summary {
      display: flex; justify-content: space-between; align-items: center; gap: 1rem;
      padding: 1.1rem 1.3rem; cursor: pointer; font-weight: 700; list-style: none;
      &::-webkit-details-marker { display: none; }
      &::after { content: "+"; font: 400 1.6rem / 1 var(--font-body); color: var(--accent); flex: none; }
    }
    &[open] summary::after { content: "–"; }
    p { padding: 0 1.3rem 1.2rem; color: var(--muted); }
  }

  /* CTA final */
  .final {
    padding-block: var(--section); text-align: center;
    background:
      radial-gradient(50rem 24rem at 50% 0%, var(--glow), transparent 70%),
      var(--bg-2);
    border-top: 1px solid var(--line);
  }
  .final__in { display: grid; gap: 1.4rem; justify-items: center; max-width: 46rem;
    p:not(.micro) { font-size: var(--step-1); color: var(--muted); }
  }

  /* Footer */
  .footer {
    padding-block: 2.5rem calc(2.5rem + var(--bar-h)); border-top: 1px solid var(--line); font-size: 0.9rem; color: var(--muted);
    a { color: var(--text); text-underline-offset: 3px; }
  }
  .footer__in { display: grid; gap: 0.6rem; justify-items: start; }
  .footer__brand { font-weight: 700; color: var(--text); }
  .footer__legal { font-size: 0.8rem; max-width: 52rem; }
  @media (min-width: 48rem) { .footer { padding-bottom: 2.5rem; } }

  /* Botón flotante de WhatsApp */
  .wa-float {
    position: fixed; right: max(1rem, env(safe-area-inset-right)); bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 60;
    width: 3.5rem; height: 3.5rem; border-radius: 50%; display: grid; place-items: center;
    background: var(--wa); color: var(--wa-ink); box-shadow: 0 0.5rem 1.4rem rgb(0 0 0 / 0.35);
    transition: bottom 0.3s ease, transform 0.2s ease;
    .icon { width: 1.9rem; height: 1.9rem; }
    &:hover { transform: scale(1.06); }
  }
  @media (prefers-reduced-motion: no-preference) {
    .wa-float { animation: pulse 2.6s ease-out infinite; }
  }
  @keyframes pulse {
    0% { box-shadow: 0 0.5rem 1.4rem rgb(0 0 0 / 0.35), 0 0 0 0 rgb(37 211 102 / 0.55); }
    70%, 100% { box-shadow: 0 0.5rem 1.4rem rgb(0 0 0 / 0.35), 0 0 0 1.1rem rgb(37 211 102 / 0); }
  }

  /* Barra fija inferior (solo móvil) */
  .sticky-bar {
    position: fixed; inset: auto 0 0 0; z-index: 55;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 0.7rem max(1rem, env(safe-area-inset-right)) calc(0.7rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    transform: translateY(100%); visibility: hidden;
    transition: transform 0.3s ease, visibility 0s 0.3s;
    p { font-weight: 700; font-size: 0.9rem; line-height: 1.25; small { color: var(--muted); font-weight: 500; } }
  }
  body.show-bar:not(.at-end) .sticky-bar { transform: none; visibility: visible; transition-delay: 0s; }
  body.show-bar:not(.at-end) .wa-float { bottom: calc(var(--bar-h) + 1rem + env(safe-area-inset-bottom)); }
  @media (min-width: 48rem) { .sticky-bar { display: none; } }
}

/* ---------- UTILIDADES: animación de aparición ---------- */
@layer utilities {
  @keyframes reveal {
    from { opacity: 0; transform: translateY(1.5rem); }
    to { opacity: 1; transform: none; }
  }
  /* Navegadores con scroll-driven animations: cero JS */
  @supports (animation-timeline: view()) {
    @media (prefers-reduced-motion: no-preference) {
      .reveal { animation: reveal linear both; animation-timeline: view(); animation-range: entry 0% entry 55%; }
    }
  }
  /* Fallback: script.js añade .rv (oculto) y luego .in (visible) */
  @supports not (animation-timeline: view()) {
    @media (prefers-reduced-motion: no-preference) {
      .reveal.rv { opacity: 0; transform: translateY(1.5rem); transition: opacity 0.6s ease, transform 0.6s ease; }
      .reveal.rv.in { opacity: 1; transform: none; }
    }
  }
}
