/* =========================================
   1. VARIABLES & DESIGN TOKENS
   ========================================= */
   :root {
    /* Paleta de colores: Slate (profesional/técnico) + Indigo (acción) */
    --color-bg-body: #f8fafc;
    --color-bg-card: #ffffff;
    --color-bg-input: #f1f5f9;
    --color-bg-highlight: #eef2ff; /* Fondo suave para fórmulas/resultados */
    
    --color-text-primary: #0f172a; /* Casi negro para lectura */
    --color-text-secondary: #475569; /* Gris medio para subtítulos */
    --color-text-muted: #94a3b8; /* Gris claro para placeholders/labels */
    
    --color-primary: #4f46e5; /* Indigo intenso */
    --color-primary-hover: #4338ca;
    --color-accent: #0ea5e9; /* Sky blue para detalles */
    
    --color-border: #e2e8f0;
    --color-error: #ef4444;
    --color-success: #10b981;
  
    /* Sombras y Elevación */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --shadow-glow: 0 0 0 4px rgba(79, 70, 229, 0.15); /* Focus ring */
  
    /* Espaciado y Radios */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 24px;
    
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  }
  
  /* =========================================
     2. RESET & BASE
     ========================================= */
  *, *::before, *::after {
    box-sizing: border-box;
  }
  
  body {
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
    background-color: var(--color-bg-body);
    /* Un patrón sutil de fondo para dar textura profesional */
    background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
    background-size: 24px 24px;
    color: var(--color-text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
  }
  
  /* =========================================
     3. LAYOUT PRINCIPAL
     ========================================= */
  .page-wrapper {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center; /* Centrado vertical en PC */
    padding: 2rem 1rem;
  }
  
  .card {
    width: 100%;
    max-width: 800px; /* Un poco más ancho para fórmulas complejas */
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255, 255, 255, 0.5); /* Borde sutil */
    overflow: hidden; /* Para que nada se salga de los bordes redondeados */
    position: relative;
  }
  
  /* Decoración superior sutil (barra de color) */
  .card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 6px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  }
  
  /* =========================================
     4. HEADER
     ========================================= */
  .card-header {
    padding: 2.5rem 2rem 1.5rem;
    text-align: center;
    border-bottom: 1px solid var(--color-border);
    background: #fff;
  }
  
  .card-header h1 {
    margin: 0 0 0.5rem;
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    color: var(--color-text-primary);
  }
  
  .card-header p {
    margin: 0;
    color: var(--color-text-secondary);
    font-size: 1rem;
    max-width: 80%;
    margin-left: auto;
    margin-right: auto;
  }
  
  /* =========================================
     5. BODY & INPUTS
     ========================================= */
  .card-body {
    padding: 2rem;
  }
  
  .input-block {
    margin-bottom: 2rem;
  }
  
  .input-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-secondary);
    margin-bottom: 0.75rem;
  }
  
  textarea#problem-input {
    width: 100%;
    min-height: 140px;
    padding: 1rem;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--color-text-primary);
    background-color: var(--color-bg-input);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    resize: vertical;
    transition: var(--transition);
    font-family: inherit;
  }
  
  textarea#problem-input::placeholder {
    color: var(--color-text-muted);
  }
  
  textarea#problem-input:hover {
    background-color: #e2e8f0; /* Un poco más oscuro al hover */
  }
  
  textarea#problem-input:focus {
    outline: none;
    background-color: #fff;
    border-color: var(--color-primary);
    box-shadow: var(--shadow-glow);
  }
  
  /* =========================================
     6. BOTONES & ACCIONES
     ========================================= */
  .primary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.875rem 1.5rem;
    background-color: var(--color-primary);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    margin-top: 1rem;
  }
  
  .primary-button:hover:not(:disabled) {
    background-color: var(--color-primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
  }
  
  .primary-button:active:not(:disabled) {
    transform: translateY(0);
  }
  
  .primary-button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    filter: grayscale(0.5);
  }
  
  /* Indicadores de estado */
  .loading {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    color: var(--color-text-secondary);
    font-weight: 500;
  }
  
  .spinner {
    width: 20px;
    height: 20px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
  
  @keyframes spin { to { transform: rotate(360deg); } }
  
  .error-message {
    margin-top: 1rem;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    background-color: #fef2f2;
    color: var(--color-error);
    border: 1px solid #fee2e2;
    font-size: 0.9rem;
    text-align: center;
    display: none; /* Se activa con JS (o textContent) */
  }
  .error-message:not(:empty) {
    display: block;
    animation: fadeIn 0.3s ease;
  }
  
  /* =========================================
     7. RESULTADOS (Transformación Visual)
     ========================================= */
  .result-section {
    margin-top: 3rem;
    border-top: 1px dashed var(--color-border);
    padding-top: 2rem;
    animation: slideUp 0.4s ease-out;
  }
  
  .result-title {
    font-size: 1.25rem;
    color: var(--color-text-primary);
    margin-bottom: 1.5rem;
    text-align: left;
    font-weight: 700;
  }
  
  .result-card {
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
  }
  
  .result-card h3 {
    font-size: 1rem;
    text-transform: uppercase;
    color: var(--color-text-secondary);
    margin-top: 0;
    margin-bottom: 1rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--color-bg-input);
    padding-bottom: 0.5rem;
    display: inline-block;
  }
  
  /* TRANSFORMAR LA LISTA (UL) EN UN GRID DASHBOARD */
  /* Esto hace que n, k y tipo se vean como tarjetas estadísticas */
  ul.key-points {
    list-style: none;
    padding: 0;
    margin: 1.5rem 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
  }
  
  ul.key-points li {
    background: var(--color-bg-input);
    padding: 1rem;
    border-radius: var(--radius-sm);
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  
  /* Estilo para las etiquetas "Total", "Elegidos", etc dentro del LI */
  ul.key-points li strong {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    margin-bottom: 0.25rem;
  }
  
  /* Estilo para los valores dentro del LI */
  ul.key-points li span {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary);
  }
  
  /* Bloque de razón */
  .reasoning {
    margin-top: 1rem;
    background-color: #fffbeb; /* Fondo amarillo muy suave para notas */
    color: #92400e;
    padding: 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    border-left: 4px solid #f59e0b;
  }
  
  /* =========================================
     8. MATEMÁTICAS & FÓRMULAS
     ========================================= */
  .formula-box {
    background-color: var(--color-bg-body);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    text-align: center;
    margin: 1.5rem 0;
    overflow-x: auto; /* Scroll si la fórmula es muy larga */
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80px;
  }
  
  /* Resultado Final Grande */
  .final-result {
    text-align: center;
    font-size: 1.1rem;
    margin-top: 2rem;
    padding: 1.5rem;
    background: var(--color-bg-highlight);
    border-radius: var(--radius-md);
    border: 1px solid #c7d2fe;
  }
  
  .final-result span#result-number {
    display: block;
    margin-top: 0.5rem;
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--color-primary);
    letter-spacing: -0.05em;
    word-break: break-all; /* Por si el número es gigante */
    line-height: 1.1;
  }
  
  /* =========================================
     9. MEDIA QUERIES (Responsive)
     ========================================= */
  @media (max-width: 600px) {
    .page-wrapper {
      padding: 1rem 0.5rem;
      align-items: flex-start; /* En móvil, mejor al top */
    }
  
    .card {
      border-radius: var(--radius-md);
      box-shadow: none; /* Más plano en móvil para ganar espacio visual */
      border: 1px solid var(--color-border);
    }
  
    .card-header {
      padding: 1.5rem 1.25rem;
    }
    
    .card-header h1 {
      font-size: 1.5rem;
    }
  
    .card-body {
      padding: 1.25rem;
    }
  
    /* En móvil, los inputs ocupan más pantalla verticalmente */
    textarea#problem-input {
      font-size: 16px; /* Evita zoom automático en iOS */
    }
  
    ul.key-points {
      grid-template-columns: 1fr; /* Uno debajo de otro en pantallas muy angostas */
    }
    
    ul.key-points li {
      flex-direction: row;
      justify-content: space-between;
      text-align: left;
    }
    
    ul.key-points li strong {
      margin-bottom: 0;
    }
  
    .final-result span#result-number {
      font-size: 2rem;
    }
  }
  
  /* Animaciones simples */
  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }
  
  @keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
  }