@layer reset, tokens, fonts, base, type, layout, components, motion, utilities;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
  body { margin: 0; }
  img, svg { display: block; max-width: 100%; }
  a { color: inherit; }
  ::selection { background: var(--press-500); color: var(--graphite-950); }
}

@layer tokens {
  :root {
    color-scheme: dark;

    /* Tier 1 — literal */
    --graphite-950: #0e0f10;
    --graphite-900: #131417;
    --graphite-800: #1c1e21;
    --graphite-700: #2a2d31;
    --steel-500: #7d8794;
    --steel-400: #97a1ad;
    --paper-50: #f4f2ed;
    --press-700: #c73f0f;
    --press-500: #ff5a1f;
    --press-300: #ffb08a;

    /* Tier 2 — semantic */
    --bg: var(--graphite-950);
    --surface: var(--graphite-900);
    --surface-raised: var(--graphite-800);
    --hairline: color-mix(in oklab, var(--paper-50) 12%, transparent);
    --text: var(--paper-50);
    --text-muted: var(--steel-400);
    --accent: var(--press-500);
    --accent-strong: var(--press-700);
    --accent-soft: var(--press-300);

    --font-display: 'Roboto Flex', system-ui, sans-serif;
    --font-body: 'InterVariable', 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;

    --measure: 62ch;
    --edge: clamp(1.25rem, 1rem + 2vw, 3rem);
  }
}

@layer fonts {
  @font-face {
    font-family: 'Roboto Flex';
    src: url('fonts/RobotoFlex-var.woff2') format('woff2');
    font-weight: 100 1000;
    font-stretch: 25% 151%;
    font-style: normal;
    font-display: swap;
  }
  @font-face {
    font-family: 'InterVariable';
    src: url('fonts/InterVariable.woff2') format('woff2');
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
  }
  @font-face {
    font-family: 'JetBrains Mono';
    src: url('fonts/JetBrainsMono.woff2') format('woff2');
    font-weight: 100 800;
    font-style: normal;
    font-display: swap;
  }
}

@layer base {
  html { color-scheme: dark; }
  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    line-height: 1.6;
    font-size: clamp(1rem, 0.95rem + 0.2vw, 1.0625rem);
    -webkit-font-smoothing: antialiased;
  }

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

  ::-webkit-scrollbar { width: 12px; }
  * { scrollbar-color: var(--steel-500) var(--graphite-950); scrollbar-width: thin; }

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

@layer type {
  h1, h2, h3 {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.05;
    text-wrap: balance;
    margin: 0;
  }

  .eyebrow {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    gap: 0.6em;
  }
  .eyebrow::before {
    content: "";
    inline-size: 1.4em;
    block-size: 1px;
    background: currentColor;
  }

  p { max-inline-size: var(--measure); text-wrap: pretty; color: var(--text-muted); }
  .lede { font-size: clamp(1.0625rem, 1rem + 0.4vw, 1.25rem); color: var(--text); }

  .mono-stat { font-family: var(--font-mono); }
}

@layer layout {
  main { display: block; }

  section {
    padding-block: clamp(4rem, 3rem + 6vw, 8rem);
    padding-inline: var(--edge);
  }

  .section-inner {
    max-inline-size: 72rem;
    margin-inline: auto;
  }

  .section-head {
    display: grid;
    gap: 1.1rem;
    max-inline-size: 42rem;
    margin-block-end: clamp(2.5rem, 2rem + 3vw, 4rem);
  }

  .stack { display: grid; gap: 1rem; }

  .below-fold {
    content-visibility: auto;
    contain-intrinsic-size: auto 900px;
  }
}

@layer components {

  /* ── Nav ─────────────────────────────────────────────────────── */
  .nav {
    position: sticky;
    inset-block-start: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-inline: var(--edge);
    padding-block: 1.1rem;
    border-block-end: 1px solid transparent;
    background: color-mix(in oklab, var(--graphite-950) 0%, transparent);
  }
  @supports ((animation-timeline: scroll()) and (animation-range: 0px 100px)) {
    .nav {
      animation: nav-solidify linear both;
      animation-timeline: scroll(root);
      animation-range: 0px 220px;
    }
  }
  @keyframes nav-solidify {
    to {
      background: color-mix(in oklab, var(--graphite-950) 88%, transparent);
      backdrop-filter: blur(10px);
      border-block-end-color: var(--hairline);
    }
  }

  .nav-mark {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 0.02em;
    text-decoration: none;
  }
  .nav-mark b { color: var(--accent); font-weight: 700; }

  /* ── Buttons ─────────────────────────────────────────────────── */
  .btn {
    display: inline-flex;
    align-items: center;
    gap: 0.6em;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    letter-spacing: 0.02em;
    text-decoration: none;
    padding-block: 0.85em;
    padding-inline: 1.3em;
    border-radius: 3px;
    min-block-size: 44px;
    transition: transform 0.15s ease, background-color 0.15s ease, color 0.15s ease;
  }
  .btn-primary {
    background: var(--accent);
    color: var(--graphite-950);
    font-weight: 600;
  }
  .btn-primary:hover { background: var(--accent-soft); transform: translateY(-1px); }
  .btn-ghost {
    border: 1px solid var(--hairline);
    color: var(--text);
  }
  .btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

  /* ── Hero ────────────────────────────────────────────────────── */
  .hero {
    position: relative;
    min-block-size: 92dvb;
    display: grid;
    align-content: center;
    gap: clamp(1.5rem, 1rem + 3vw, 2.5rem);
    padding-inline: var(--edge);
    overflow: clip;
    isolation: isolate;
  }

  .hero-rig {
    position: absolute;
    inset: 0;
    z-index: -1;
    background:
      radial-gradient(60% 50% at 82% 18%, color-mix(in oklab, var(--accent) 22%, transparent), transparent 70%),
      repeating-linear-gradient(90deg, var(--hairline) 0 1px, transparent 1px 96px),
      repeating-linear-gradient(0deg, var(--hairline) 0 1px, transparent 1px 96px);
    -webkit-mask-image: linear-gradient(to bottom, black, transparent 92%);
            mask-image: linear-gradient(to bottom, black, transparent 92%);
  }

  .hero h1 {
    font-size: clamp(2.75rem, 2rem + 6vw, 6.5rem);
    max-inline-size: 16ch;
  }

  .hero .lede { max-inline-size: 46ch; }

  .hero-actions { display: flex; flex-wrap: wrap; gap: 1rem; margin-block-start: 0.5rem; }

  /* ── Compaction heading (signature motion) ──────────────────── */
  .compact {
    font-stretch: 84%;
    font-variation-settings: 'opsz' 60, 'GRAD' 0;
    opacity: 1;
  }
  @supports ((animation-timeline: view()) and (animation-range: entry)) {
    .compact {
      animation: compact-in linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 45%;
    }
  }
  @keyframes compact-in {
    from {
      font-stretch: 145%;
      font-variation-settings: 'opsz' 28, 'GRAD' -90;
      opacity: 0.35;
      letter-spacing: 0.01em;
    }
    to {
      font-stretch: 84%;
      font-variation-settings: 'opsz' 60, 'GRAD' 0;
      opacity: 1;
      letter-spacing: -0.01em;
    }
  }

  /* ── Stages (how it compacts) ─────────────────────────────────── */
  .stages {
    display: grid;
    gap: 0;
    border-inline-start: 1px solid var(--hairline);
    margin-inline-start: clamp(0.5rem, 1vw, 1rem);
  }

  .stage {
    position: relative;
    padding-inline-start: clamp(1.75rem, 2vw, 3rem);
    padding-block: clamp(1.75rem, 2vw, 2.75rem);
    display: grid;
    gap: 0.6rem;
    max-inline-size: 46rem;
  }

  .stage::before {
    content: "";
    position: absolute;
    inset-inline-start: -1px;
    inset-block-start: 0;
    inline-size: 2px;
    block-size: 0%;
    background: var(--accent);
    transform-origin: top;
  }
  @supports ((animation-timeline: view()) and (animation-range: entry)) {
    .stage::before {
      animation: draw-line linear both;
      animation-timeline: view();
      animation-range: entry 10% cover 60%;
    }
  }
  @keyframes draw-line { to { block-size: 100%; } }

  .stage-index {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--accent);
    letter-spacing: 0.08em;
  }

  .stage h3 { font-size: clamp(1.35rem, 1.2rem + 1vw, 1.9rem); }

  /* ── Gauge / cobro por resultado ───────────────────────────────── */
  .gauge {
    border: 1px solid var(--hairline);
    border-radius: 4px;
    padding: clamp(1.5rem, 1rem + 2vw, 2.5rem);
    background: linear-gradient(180deg, var(--surface), var(--surface-raised));
    display: grid;
    gap: clamp(1.25rem, 1rem + 2vw, 2rem);
  }

  .gauge-track {
    position: relative;
    block-size: 3px;
    background: var(--hairline);
    border-radius: 2px;
    overflow: clip;
  }
  .gauge-fill {
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    inline-size: 8%;
    background: linear-gradient(90deg, transparent, var(--accent));
  }
  @supports ((animation-timeline: view()) and (animation-range: entry)) {
    .gauge-fill {
      animation: fill-gauge linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 70%;
    }
  }
  @keyframes fill-gauge { to { inline-size: 100%; } }

  .gauge-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 1rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-muted);
  }
  .gauge-row strong { color: var(--text); font-weight: 500; }

  /* ── ICP list ──────────────────────────────────────────────────── */
  .icp-grid {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 1px;
    background: var(--hairline);
    border: 1px solid var(--hairline);
    border-radius: 4px;
    overflow: clip;
  }
  /* Columnas fijas (no auto-fit) para que 6 ítems nunca dejen una celda huérfana. */
  @media (min-width: 36rem) {
    .icp-grid { grid-template-columns: repeat(2, 1fr); }
  }
  @media (min-width: 60rem) {
    .icp-grid { grid-template-columns: repeat(3, 1fr); }
  }
  .icp-item {
    background: var(--surface);
    padding: 1.4rem 1.5rem;
    display: grid;
    gap: 0.4rem;
  }
  .icp-item .k {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    color: var(--accent);
    text-transform: uppercase;
  }
  .icp-item .v { color: var(--text); font-size: 0.98rem; }

  /* ── Final CTA ─────────────────────────────────────────────────── */
  .cta-final {
    text-align: center;
    display: grid;
    justify-items: center;
    gap: 1.5rem;
  }
  .cta-final h2 { max-inline-size: 20ch; }
  .cta-secondary {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-block-start: -0.75rem;
  }
  .cta-secondary a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
  .cta-secondary a:hover { color: var(--accent-soft); }

  /* ── Footer ────────────────────────────────────────────────────── */
  footer {
    border-block-start: 1px solid var(--hairline);
    padding: var(--edge);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 1rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-muted);
  }
}

@layer motion {
  @media (prefers-reduced-motion: reduce) {
    .nav, .compact, .stage::before, .gauge-fill {
      animation: none !important;
    }
    .compact {
      font-stretch: 84%;
      font-variation-settings: 'opsz' 60, 'GRAD' 0;
      opacity: 1;
    }
    .stage::before { block-size: 100%; }
    .gauge-fill { inline-size: 100%; }
  }
}

@layer utilities {
  .visually-hidden {
    position: absolute;
    inline-size: 1px; block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}
