/* ==========================================================================
   ju4nacademy · styles.css
   --------------------------------------------------------------------------
   ÍNDICE
   0. Orden de capas
   1. Tokens (color, tipografía, espaciado, forma, movimiento)
   2. Reset y base
   3. Layout (contenedor, secciones, split, grid)
   4. Componentes
      4.1  Botones
      4.2  Header y navegación
      4.3  Borde lumínico (.glow)
      4.4  Hero y terminal
      4.5  Lista de valor
      4.6  Ruta interactiva (chips)
      4.7  Tarjetas de curso
      4.8  Formulario de contacto
      4.9  Footer
      4.10 Mini-bot
   5. Utilidades y movimiento
   ========================================================================== */

/* 0. ORDEN DE CAPAS ------------------------------------------------------ */
@layer tokens, reset, base, layout, components, utilities;


/* 1. TOKENS -------------------------------------------------------------- */
@layer tokens {
  :root {
    /* Color · claro (por defecto) */
    --c-bg:        #ffffff;
    --c-surface:   #f5f6fb;
    --c-text:      #0f1222;
    --c-muted:     #596078;
    --c-line:      #e2e5f0;
    --c-accent:    #3b4cf0;
    --c-on-accent: #ffffff;
    --c-warm:      #ffd84d;
    --c-danger:    #d93b3b;

    /* Tipografía */
    --font-head: "Bricolage Grotesque", system-ui, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
    --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

    --fs-xs:   .75rem;
    --fs-sm:   .875rem;
    --fs-base: 1rem;
    --fs-lg:   1.15rem;
    --fs-h3:   1.25rem;
    --fs-h2:   clamp(1.8rem, 5vw, 3rem);
    --fs-h1:   clamp(2.2rem, 6.5vw, 3.9rem);

    /* Espaciado (escala de 4px) */
    --sp-1: .25rem;  --sp-2: .5rem;   --sp-3: .75rem;  --sp-4: 1rem;
    --sp-5: 1.5rem;  --sp-6: 2rem;    --sp-7: 3rem;    --sp-8: 4.5rem;

    /* Forma */
    --r-sm:   8px;
    --r-md:   12px;
    --r-lg:   16px;
    --r-pill: 999px;

    /* Layout */
    --w-page:   1080px;
    --h-header: 60px;

    /* Capas (z-index) */
    --z-header: 20;
    --z-bot:    30;
    --z-skip:   99;

    /* Movimiento */
    --ease:     cubic-bezier(.2, .7, .2, 1);
    --dur-fast: .2s;
    --dur-base: .3s;

    color-scheme: light;
  }

  [data-theme="dark"] {
    --c-bg:        #0d0f1a;
    --c-surface:   #151829;
    --c-text:      #eceefb;
    --c-muted:     #9aa1bd;
    --c-line:      #262b45;
    --c-accent:    #8c9bff;
    --c-on-accent: #0d0f1a;
    --c-danger:    #ff7b7b;
    color-scheme: dark;
  }
}


/* 2. RESET Y BASE -------------------------------------------------------- */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  h1, h2, h3, p, dl, dd, ol, ul { margin: 0; padding: 0; }
  ol, ul { list-style: none; }
  img, svg { display: block; max-width: 100%; }
  button, input, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; }
}

@layer base {
  html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--h-header) + var(--sp-4));
  }

  body {
    background-color: var(--c-bg);
    color: var(--c-text);
    font: 400 var(--fs-base)/1.65 var(--font-body);
    -webkit-font-smoothing: antialiased;
  }

  h1, h2, h3 {
    font-family: var(--font-head);
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -.02em;
    text-wrap: balance;
  }
  h1 { font-size: var(--fs-h1); margin-bottom: var(--sp-5); }
  h2 { font-size: var(--fs-h2); margin-bottom: var(--sp-5); }
  h1 em { font-style: normal; color: var(--c-accent); }

  p { max-width: 62ch; margin-bottom: var(--sp-4); }
  a { color: inherit; }

  :focus-visible {
    outline: 2px solid var(--c-accent);
    outline-offset: 3px;
  }
  ::selection { background: var(--c-accent); color: var(--c-on-accent); }
}


/* 3. LAYOUT -------------------------------------------------------------- */
@layer layout {
  main > section,
  .footer {
    max-width: var(--w-page);
    margin-inline: auto;
    padding: var(--sp-8) var(--sp-5);
  }

  .split { display: grid; gap: var(--sp-6); }
  @media (min-width: 800px) {
    .split { grid-template-columns: 1fr 1.2fr; gap: var(--sp-7); align-items: start; }
  }

  .grid { display: grid; gap: var(--sp-4); }
  @media (min-width: 640px) { .grid { grid-template-columns: repeat(2, 1fr); } }
  @media (min-width: 960px) {
    .grid { grid-template-columns: repeat(3, 1fr); }
    .grid > :first-child { grid-column: span 2; }
  }
}


/* 4. COMPONENTES --------------------------------------------------------- */
@layer components {

  /* 4.1 Botones ---------------------------------------------------------- */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: .8rem 1.3rem;
    border: 1px solid var(--c-line);
    border-radius: var(--r-md);
    background: transparent;
    font: 600 var(--fs-sm)/1 var(--font-mono);
    text-decoration: none;
    transition: transform var(--dur-fast) var(--ease),
                border-color var(--dur-fast), opacity var(--dur-fast);
  }
  .btn:hover { border-color: var(--c-accent); transform: translateY(-2px); }
  .btn:disabled { opacity: .6; cursor: progress; transform: none; }
  .btn--primary,
  .btn.primary {
    background: var(--c-accent);
    border-color: var(--c-accent);
    color: var(--c-on-accent);
  }

  .icon-btn {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--c-line);
    border-radius: var(--r-sm);
    background: none;
    transition: border-color var(--dur-fast);
  }
  .icon-btn:hover { border-color: var(--c-accent); }

  /* 4.2 Header y navegación --------------------------------------------- */
  .top {
    position: sticky;
    top: 0;
    z-index: var(--z-header);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--h-header);
    padding: var(--sp-2) var(--sp-5);
    border-bottom: 1px solid var(--c-line);
    background: color-mix(in srgb, var(--c-bg) 80%, transparent);
    backdrop-filter: blur(12px);
  }

  .logo { font: 600 var(--fs-base) var(--font-mono); text-decoration: none; }
  .logo span { color: var(--c-accent); }

  .top nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    display: none;
    flex-direction: column;
    gap: var(--sp-1);
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--c-line);
    background: var(--c-bg);
  }
  .top nav.open { display: flex; }
  .top nav a {
    padding: var(--sp-2) 0;
    color: var(--c-muted);
    font: var(--fs-sm) var(--font-mono);
    text-decoration: none;
    transition: color var(--dur-fast);
  }
  .top nav a:hover { color: var(--c-accent); }

  @media (min-width: 760px) {
    .menu { display: none; }
    .top nav {
      position: static;
      display: flex;
      flex-direction: row;
      align-items: center;
      gap: var(--sp-5);
      padding: 0;
      border: 0;
      background: none;
    }
  }

  /* 4.3 Borde lumínico (sigue al cursor, ver app.js) --------------------- */
  .glow {
    position: relative;
    border: 1px solid var(--c-line);
    border-radius: var(--r-lg);
    background: var(--c-surface);
  }
  .glow::before {
    content: "";
    position: absolute;
    inset: -1px;
    padding: 1px;
    border-radius: inherit;
    background: radial-gradient(220px circle at var(--x, 50%) var(--y, -60%),
                                var(--c-accent), transparent 70%);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
            mask-composite: exclude;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-base);
  }
  .glow:hover::before,
  .glow:focus-within::before { opacity: 1; }

  /* 4.4 Hero y terminal -------------------------------------------------- */
  .tag {
    margin-bottom: var(--sp-4);
    color: var(--c-accent);
    font: 600 var(--fs-xs) var(--font-mono);
    letter-spacing: .04em;
  }
  .lead { max-width: 56ch; color: var(--c-muted); font-size: var(--fs-lg); }

  .hero { padding-top: 5rem; }
  .cta { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-block: var(--sp-5) var(--sp-6); }

  .term { max-width: 560px; overflow: hidden; }
  .term-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: .6rem var(--sp-4);
    border-bottom: 1px solid var(--c-line);
    color: var(--c-muted);
    font: var(--fs-xs) var(--font-mono);
  }
  .term-bar i { width: 9px; height: 9px; border-radius: 50%; background: var(--c-line); }
  .term-bar span { margin-left: auto; }
  .term pre {
    min-height: 7.5rem;
    padding: var(--sp-4);
    font: var(--fs-sm)/1.7 var(--font-mono);
    white-space: pre-wrap;
  }
  .term pre::after { content: "▍"; color: var(--c-accent); animation: blink 1s steps(2) infinite; }

  .stats { display: flex; gap: var(--sp-6); margin-top: var(--sp-6); }
  .stats dt { color: var(--c-muted); font: var(--fs-xs) var(--font-mono); }
  .stats dd { font: 800 2rem/1.2 var(--font-head); }

  /* 4.5 Lista de valor --------------------------------------------------- */
  .list > li {
    display: grid;
    gap: var(--sp-1);
    padding: var(--sp-4) 0;
    border-top: 1px solid var(--c-line);
    transition: padding-left var(--dur-base) var(--ease);
  }
  .list > li:hover { padding-left: var(--sp-3); }
  .list b { color: var(--c-accent); font: 600 var(--fs-sm) var(--font-mono); }
  .list span { color: var(--c-muted); }

  /* 4.6 Ruta interactiva ------------------------------------------------- */
  .chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-4); }
  .chip {
    padding: .55rem var(--sp-4);
    border: 1px solid var(--c-line);
    border-radius: var(--r-pill);
    background: none;
    font: var(--fs-sm) var(--font-mono);
    transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
  }
  .chip:hover { border-color: var(--c-accent); }
  .chip[aria-checked="true"] {
    background: var(--c-accent);
    border-color: var(--c-accent);
    color: var(--c-on-accent);
  }

  .route { min-height: 9rem; padding: var(--sp-5); font: var(--fs-sm)/1.8 var(--font-mono); }
  .route .cmd { color: var(--c-accent); }
  .route ol { margin-top: var(--sp-2); padding-left: 1.4rem; list-style: decimal; }
  .route li::marker { color: var(--c-accent); }

  /* 4.7 Tarjetas de curso ------------------------------------------------ */
  .card {
    display: block;
    padding: var(--sp-5);
    text-decoration: none;
    transition: transform var(--dur-base) var(--ease);
  }
  .card:hover { transform: translateY(-4px); }
  .card small { color: var(--c-accent); font: var(--fs-xs) var(--font-mono); }
  .card h3 { margin: var(--sp-2) 0; font-size: var(--fs-h3); }
  .card p { margin: 0; color: var(--c-muted); font-size: .92rem; }
  .card .meta { margin-top: var(--sp-4); color: var(--c-muted); font: var(--fs-xs) var(--font-mono); }

  .pills { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-block: var(--sp-4) var(--sp-5); }
  .pills span {
    padding: .3rem var(--sp-3);
    border: 1px solid var(--c-line);
    border-radius: var(--r-pill);
    color: var(--c-muted);
    font: var(--fs-xs) var(--font-mono);
  }

  /* 4.8 Formulario de contacto ------------------------------------------ */
  .form { display: grid; gap: var(--sp-4); max-width: 640px; padding: var(--sp-5); }
  @media (min-width: 640px) {
    .form { grid-template-columns: 1fr 1fr; }
    .form .full { grid-column: 1 / -1; }
  }

  .form label { display: grid; gap: var(--sp-2); color: var(--c-muted); font: var(--fs-xs) var(--font-mono); }
  .form input,
  .form select,
  .form textarea {
    width: 100%;
    padding: .75rem .9rem;
    border: 1px solid var(--c-line);
    border-radius: var(--r-md);
    background: var(--c-bg);
    font: var(--fs-base) var(--font-body);
    transition: border-color var(--dur-fast);
  }
  .form textarea { resize: vertical; }
  .form input:focus,
  .form select:focus,
  .form textarea:focus { outline: none; border-color: var(--c-accent); }
  .form [aria-invalid="true"] { border-color: var(--c-danger); }

  .err { min-height: 1.2em; color: var(--c-danger); }
  .hp  { position: absolute; left: -9999px; }

  .spin {
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
  }
  .spin[hidden] { display: none; }

  .status { margin: 0; color: var(--c-accent); font: var(--fs-sm) var(--font-mono); }
  .status a { color: inherit; }

  /* 4.9 Footer ----------------------------------------------------------- */
  .footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: var(--sp-2);
    border-top: 1px solid var(--c-line);
    color: var(--c-muted);
    font: var(--fs-xs) var(--font-mono);
  }
  .footer p { margin: 0; max-width: none; }

  /* 4.4b Hero (dos columnas), badge y datos clave ------------------------ */
  .hero { display: grid; gap: var(--sp-6); align-items: center; }
  @media (min-width: 900px) { .hero { grid-template-columns: 1.15fr 1fr; gap: var(--sp-7); } }
  .hero .cta { margin-bottom: 0; }

  .badge {
    display: inline-block;
    margin-bottom: var(--sp-4);
    padding: .3rem var(--sp-3);
    border-radius: var(--r-pill);
    background: var(--c-warm);
    color: #0f1222;
    font: 600 var(--fs-xs) var(--font-mono);
  }

  /* La terminal conserva su look oscuro en ambos temas */
  .term { border: 0; border-radius: var(--r-lg); background: #0f1222; color: #eceefb; box-shadow: 0 24px 60px -24px rgb(15 18 34 / .45); }
  .term-bar { border-bottom-color: #262b45; color: #9aa1bd; }
  .term-bar i { background: #262b45; }
  .term pre::after { color: #8c9bff; }

  .facts { padding-block: 0; }
  .stats {
    gap: 0;
    margin-top: 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    border: 1px solid var(--c-line);
    border-radius: var(--r-lg);
    background: var(--c-surface);
  }
  .stats > div { display: flex; flex-direction: column-reverse; padding: var(--sp-4) var(--sp-5); }
  .stats > div:nth-child(n+3) { border-top: 1px solid var(--c-line); }
  .stats > div:nth-child(even) { border-left: 1px solid var(--c-line); }
  @media (min-width: 800px) {
    .stats { grid-template-columns: repeat(4, 1fr); }
    .stats > div:nth-child(n+3) { border-top: 0; }
    .stats > div + div { border-left: 1px solid var(--c-line); }
  }

  /* 4.4c Encabezado de sección ------------------------------------------- */
  .section-head { margin-bottom: var(--sp-6); }
  .section-head h2 { margin-bottom: var(--sp-3); }
  .section-head .lead { margin: 0; }

  /* 4.7b Tarjeta de curso: nivel y habilidades --------------------------- */
  .card-top { display: flex; align-items: center; justify-content: space-between; }
  .level { display: inline-flex; gap: 4px; }
  .level i { width: 8px; height: 8px; border-radius: 50%; background: var(--c-line); }
  .level i.on { background: var(--c-accent); }
  .skills { display: flex; flex-wrap: wrap; gap: var(--sp-1); margin-top: var(--sp-4); }
  .skills li {
    padding: .15rem .55rem;
    border-radius: var(--r-sm);
    background: var(--c-surface);
    color: var(--c-muted);
    font: var(--fs-xs) var(--font-mono);
  }
  .card:hover h3 { color: var(--c-accent); }

  /* 4.5b Bloques "cómo aprendes" ----------------------------------------- */
  .features { display: grid; gap: var(--sp-5); }
  @media (min-width: 800px) { .features { grid-template-columns: repeat(3, 1fr); gap: var(--sp-6); } }
  .features li { padding-top: var(--sp-4); border-top: 2px solid var(--c-accent); }
  .features h3 { margin-bottom: var(--sp-2); font-size: var(--fs-h3); }
  .features p { color: var(--c-muted); margin: 0; }

  /* 4.6b Preguntas frecuentes -------------------------------------------- */
  .faq { max-width: 760px; border-top: 1px solid var(--c-line); }
  .faq details { border-bottom: 1px solid var(--c-line); }
  .faq summary {
    display: flex;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: var(--sp-4) 0;
    font: 600 var(--fs-lg) var(--font-head);
    list-style: none;
    cursor: pointer;
  }
  .faq summary::-webkit-details-marker { display: none; }
  .faq summary::after { content: "+"; color: var(--c-accent); transition: transform var(--dur-fast); }
  .faq details[open] summary::after { transform: rotate(45deg); }
  .faq details p { color: var(--c-muted); }

  /* 4.10 Mini-bot -------------------------------------------------------- */
  .bot { position: fixed; right: var(--sp-4); bottom: var(--sp-4); z-index: var(--z-bot); }

  .bot-fab {
    width: 54px;
    height: 54px;
    border: 1px solid var(--c-accent);
    border-radius: 50%;
    background: var(--c-surface);
    color: var(--c-accent);
    font: 600 var(--fs-base) var(--font-mono);
    box-shadow: 0 0 24px color-mix(in srgb, var(--c-accent) 30%, transparent);
    transition: transform var(--dur-fast) var(--ease);
  }
  .bot-fab:hover { transform: scale(1.08); }

  .bot-panel {
    position: absolute;
    right: 0;
    bottom: 66px;
    display: flex;
    flex-direction: column;
    width: min(360px, calc(100vw - 2rem));
    overflow: hidden;
    animation: pop var(--dur-fast) var(--ease);
  }
  .bot-panel[hidden] { display: none; }
  .bot-panel > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .6rem var(--sp-4);
    border-bottom: 1px solid var(--c-line);
    font: var(--fs-sm) var(--font-mono);
  }

  .bot-log {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    height: min(300px, 45vh);
    padding: var(--sp-4);
    overflow-y: auto;
  }
  .msg {
    max-width: 88%;
    padding: .55rem var(--sp-3);
    border: 1px solid var(--c-line);
    border-radius: var(--r-md);
    font-size: .9rem;
    line-height: 1.5;
  }
  .msg.bot { align-self: flex-start; background: var(--c-bg); }
  .msg.me  { align-self: flex-end; background: var(--c-accent); border-color: var(--c-accent); color: var(--c-on-accent); }
  .msg a   { color: inherit; font-weight: 700; }

  .bot-quick { display: flex; flex-wrap: wrap; gap: .4rem; padding: 0 var(--sp-4) var(--sp-3); }
  .bot-quick .chip { padding: .3rem .7rem; font-size: var(--fs-xs); }

  #bot-form { display: flex; gap: var(--sp-2); padding: var(--sp-3); border-top: 1px solid var(--c-line); }
  #bot-in {
    flex: 1;
    min-width: 0;
    padding: .55rem var(--sp-3);
    border: 1px solid var(--c-line);
    border-radius: var(--r-md);
    background: var(--c-bg);
  }
  #bot-in:focus { outline: none; border-color: var(--c-accent); }
  #bot-form .btn { padding: .5rem var(--sp-4); }
}


/* 5. UTILIDADES Y MOVIMIENTO -------------------------------------------- */
@layer utilities {
  .skip {
    position: absolute;
    top: var(--sp-2);
    left: -999px;
    z-index: var(--z-skip);
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--r-sm);
    background: var(--c-accent);
    color: var(--c-on-accent);
  }
  .skip:focus { left: var(--sp-2); }

  .reveal { opacity: 0; transform: translateY(18px); transition: opacity .6s, transform .6s var(--ease); }
  .reveal.in { opacity: 1; transform: none; }
}

@keyframes blink { 50% { opacity: 0; } }
@keyframes spin  { to  { transform: rotate(360deg); } }
@keyframes pop   { from { opacity: 0; transform: translateY(8px) scale(.97); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .reveal { opacity: 1; transform: none; }
}
