/* ============================================================
   CHEMARIO 2022 – style.css
   Sistema de diseño completo extraído de Chemario.html
   ============================================================ */

/* ─── TOKENS DE DISEÑO ─── */
:root {
    --bg: #faf9f5;
    --surface: #efe9de;
    --surface-hover: #e8e0d2;
    --text-main: #141413;
    --text-muted: #6c6a64;
    --border: rgba(20, 20, 19, 0.08);
    --border-hover: rgba(20, 20, 19, 0.16);
    --nav-bg: rgba(250, 249, 245, 0.9);
    --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 3px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 20px rgba(44, 44, 42, 0.15);
    --radius-md: 12px;
    --radius-lg: 16px;

    /* Acento de marca (uso puntual: hero, foco/hover de botones de header) */
    --accent: #cc785c;
    --accent-active: #a9583e;

    /* Tipografía display (títulos) — cuerpo/UI sigue en Inter */
    --font-display: 'Cormorant Garamond', 'EB Garamond', Georgia, serif;

    /* Colores por sección */
    --c-alg: #2c2c2a;
    --c-geo: #6b3a2a;
    --c-tri: #2a5c4a;
    --c-fun: #4a2a6a;
    --c-dif: #5a3010;
    --c-sum: #1a6038;
    --c-ser: #1a4868;
    --c-int: #6a3c10;

    --num-bg: #e8e0d2;
    --head-text: white;
    --num-text: #57534a;

    /* ── Mejoras UI/UX post-refactor ── */
    --transition-fast: 0.2s ease;
    --transition-main: 0.3s ease;
    --transition-spring: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    --focus-ring: 0 0 0 3px rgba(20, 20, 19, 0.18);
}

/* ─── MODO OSCURO ─── */
html.dark {
    --bg: #181715;
    --surface: #252320;
    --surface-hover: #2f2c27;
    --text-main: #faf9f5;
    --text-muted: #a09d96;
    --border: rgba(250, 249, 245, 0.1);
    --border-hover: rgba(250, 249, 245, 0.18);
    --nav-bg: rgba(24, 23, 21, 0.85);
    --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 3px 12px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 20px rgba(255, 255, 255, 0.1);

    --accent: #e0987a;
    --accent-active: #cc785c;

    --c-alg: #d4d4d0;
    --c-geo: #d89680;
    --c-tri: #7cc0a0;
    --c-fun: #a684cd;
    --c-dif: #c68e60;
    --c-sum: #68c494;
    --c-ser: #6ba8d8;
    --c-int: #d89e60;

    --num-bg: #2f2c27;
    --head-text: #181715;
    --num-text: #d8d3c8;
    --focus-ring: 0 0 0 3px rgba(250, 249, 245, 0.12);
}

/* ─── RESET BASE ─── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg);
    color: var(--text-main);
    transition: background-color 0.4s ease, color 0.4s ease;
    overflow-x: hidden;
    line-height: 1.5;
    /* Mejora: text rendering más nítido */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ─── HEADER ─── */
header {
    position: relative;
    padding: 4rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    overflow: hidden;
    background: var(--bg);
    color: var(--text-main);
    z-index: 1;
}

.header-bg {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background:
        radial-gradient(circle at 50% 50%, rgba(107, 58, 42, 0.12), transparent 60%),
        radial-gradient(circle at 80% 20%, rgba(42, 92, 74, 0.12), transparent 50%),
        radial-gradient(circle at 25% 80%, rgba(204, 120, 92, 0.14), transparent 55%);
    animation: rotateBg 20s linear infinite;
    z-index: -1;
    opacity: 0.6;
}

html.dark .header-bg {
    opacity: 0.85;
}

@keyframes rotateBg {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

header h1 {
    font-family: var(--font-display);
    font-size: clamp(2.5rem, 6vw, 4rem); /* Mejora: fluid type */
    font-weight: 500;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
    color: var(--text-main);
    animation: slideDown 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

header p {
    font-size: 1.1rem;
    color: var(--text-muted);
    max-width: 600px;
    animation: fadeIn 1.2s ease-out;
}

/* ─── BOTÓN DE TEMA ─── */
.theme-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 8px 16px;
    border-radius: 99px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all var(--transition-main);
    /* Mejora: focus visible accesible */
}

.theme-btn:hover {
    background: var(--surface-hover);
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.theme-btn:focus-visible, .contact-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(204, 120, 92, 0.35);
}

/* ─── BOTÓN DE CONTACTO ─── */
.contact-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    background: var(--surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 8px 16px;
    border-radius: 99px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all var(--transition-main);
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.contact-btn:hover {
    background: var(--surface-hover);
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

/* ─── NAVEGACIÓN ─── */
nav {
    position: sticky;
    top: 0;
    background: var(--nav-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    padding: 0 1rem;
    display: flex;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
    /* Mejora: scroll suave en iOS */
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 1024px) {
    nav { justify-content: center; }
}

nav::-webkit-scrollbar { display: none; }

.nav-container {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 0;
    margin: 0 auto;
}

nav button {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.75rem 1.25rem;
    border-radius: 99px;
    cursor: pointer;
    transition: all var(--transition-main);
    white-space: nowrap;
}

nav button:hover {
    color: var(--text-main);
    background: var(--surface-hover);
}

nav button.active {
    color: var(--surface);
    background: var(--text-main);
    box-shadow: var(--shadow-md);
}

nav button:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ─── CONTENEDOR PRINCIPAL ─── */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 3rem 1.5rem 6rem;
}

/* ─── SECCIONES ─── */
.section {
    display: none;
    animation: fadeIn 0.5s ease-out;
}

.section.active { display: block; }

/* ─── ENCABEZADO DE SECCIÓN ─── */
.sec-hdr {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 2.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}

.sec-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--head-text);
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
    flex-shrink: 0; /* Mejora: no colapsar en pantallas pequeñas */
}

.sec-icon::after {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.3), transparent);
    transform: skewX(-20deg);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0%   { left: -100%; }
    20%  { left: 200%; }
    100% { left: 200%; }
}

.sec-title {
    font-family: var(--font-display);
    font-size: 2.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.sec-sub {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ─── GRID DE TARJETAS ─── */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

.grid-wide { grid-column: 1 / -1; }

@media (min-width: 1024px) {
    .grid { grid-template-columns: repeat(2, 1fr); }
}

/* ─── TARJETA ─── */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-spring);
    opacity: 0;
    transform: translateY(30px);
    /* Mejora: aceleración por GPU */
    will-change: transform, box-shadow;
}

.card.visible {
    opacity: 1;
    transform: translateY(0);
}

.card:hover {
    transform: translateY(-6px) scale(1.01);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    border-color: var(--border-hover);
}

/* Mejora: no aplicar hover al card si contiene fórmula grande (accesibilidad táctil) */
@media (hover: none) {
    .card:hover { transform: none; box-shadow: var(--shadow-sm); }
}

.card-head {
    padding: 1rem 1.5rem;
    font-weight: 700;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--head-text);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.card-body { padding: 1.5rem; }

/* ─── FILA DE FÓRMULA ─── */
.f-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: var(--radius-md);
    background: var(--bg);
    border: 1px solid transparent;
    transition: all var(--transition-main);
    opacity: 0;
    transform: translateX(-20px);
    /* Mejora: cursor texto para fórmulas */
    cursor: default;
}

.f-row.visible {
    opacity: 1;
    transform: translateX(0);
}

.f-row:hover {
    background: var(--surface-hover);
    border-color: var(--border);
    transform: translateX(4px);
}

.f-row:last-child { margin-bottom: 0; }

/* Número de fórmula */
.f-num {
    min-width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--num-bg);
    color: var(--num-text);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-main);
    user-select: none; /* Mejora: no seleccionable */
}

.f-row:hover .f-num {
    transform: scale(1.1) rotate(5deg);
    background: var(--text-main);
    color: var(--surface);
}

.f-content {
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
    font-size: 1.05rem;
    padding: 0.25rem 0;
}

.f-content::-webkit-scrollbar { display: none; }

/* ─── ELEMENTOS DE APOYO ─── */
.f-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    font-style: italic;
}

.f-big {
    background: var(--bg);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin: 0.75rem 0;
    text-align: center;
    /* overflow-x: auto activa el scroll SOLO cuando el contenido
       desborda el ancho del contenedor. Si cabe, no aparece ningún
       control de desplazamiento. */
    overflow-x: auto;
    border: 1px solid var(--border);
    transition: all var(--transition-main);
    font-size: 1.15rem;
    /* Oculta la barra nativa en Firefox */
    scrollbar-width: none;
}

/* Oculta la barra nativa en Chrome/Safari/Edge */
.f-big::-webkit-scrollbar { display: none; }

.f-big:hover {
    border-color: var(--border-hover);
    box-shadow: inset 0 0 0 1px var(--border-hover);
}

/* ─── ETIQUETAS / TAGS ─── */
.tag {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 99px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: var(--num-bg);
    color: var(--num-text);
    margin: 0.5rem 0;
    user-select: none;
}

/* ─── DISCRIMINANTE ─── */
.disc-box {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin: 0.75rem 0;
}

.disc {
    flex: 1;
    min-width: 120px;
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    border-left: 4px solid;
    background: var(--bg);
    transition: transform var(--transition-main);
}

.disc:hover { transform: translateY(-2px); }
.disc.pos { border-color: #10b981; }
.disc.zer { border-color: #f59e0b; }
.disc.neg { border-color: #ef4444; }

/* ─── TABLA TRIGONOMÉTRICA ─── */
.trig-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
    margin: 1rem 0;
    display: block;
    /* En móviles la tabla puede ser más ancha que el contenedor;
       overflow-x: auto habilita el scroll solo en ese caso.
       Las reglas siguientes ocultan la barra nativa del navegador
       para no mostrar flechas ni scrollbar cuando no hay desborde. */
    overflow-x: auto;
    scrollbar-width: none; /* Firefox */
}

/* Chrome / Safari / Edge */
.trig-table::-webkit-scrollbar { display: none; }

.trig-table th,
.trig-table td {
    padding: 0.75rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    white-space: nowrap; /* Mejora: evita quiebre de celdas */
}

.trig-table th:last-child,
.trig-table td:last-child { border-right: none; }

.trig-table tr:last-child td { border-bottom: none; }

.trig-table th {
    background: var(--surface-hover);
    font-weight: 600;
    color: var(--text-main);
    position: sticky; /* Mejora: header sticky al scroll horizontal */
    top: 0;
}

/* ─── BOTÓN VOLVER ARRIBA ─── */
#btt {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--text-main);
    color: var(--surface);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
    transition: all var(--transition-spring);
    z-index: 1000;
    /* Mejora: área táctil mínima accesible */
    min-width: 44px;
    min-height: 44px;
}

#btt.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#btt:hover {
    transform: translateY(-5px) scale(1.1);
    box-shadow: 0 15px 25px -5px rgba(0, 0, 0, 0.2);
}

#btt:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ─── MATHJAX OVERRIDE ─── */
mjx-container {
    display: inline-block !important;
    margin: 0 !important;
    max-width: 100%;
    /* El scroll aparece solo si la fórmula excede el ancho disponible.
       scrollbar-width y ::-webkit-scrollbar ocultan la barra nativa
       manteniendo la funcionalidad de desplazamiento al tocar/arrastrar. */
    overflow-x: auto;
    scrollbar-width: none; /* Firefox */
}

mjx-container::-webkit-scrollbar { display: none; } /* Chrome/Safari/Edge */

/* ─── ANIMACIONES ─── */
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-30px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ─── MEJORAS UI/UX ADICIONALES (Post-Refactor) ─── */

/* Selección de texto con color de marca */
::selection {
    background: rgba(44, 44, 42, 0.15);
    color: var(--text-main);
}
html.dark ::selection {
    background: rgba(255, 255, 255, 0.15);
}

/* Mejora: scroll suave nativo */
html { scroll-behavior: smooth; }

/* Mejora: skip-to-content para lectores de pantalla */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--text-main);
    color: var(--surface);
    padding: 8px 16px;
    border-radius: 0 0 8px 0;
    z-index: 9999;
    font-weight: 700;
    transition: top var(--transition-fast);
}
.skip-link:focus { top: 0; }

/* Mejora: indicador de sección activa en la nav con línea inferior */
nav button.active::after {
    content: '';
    display: block;
    height: 2px;
    background: var(--surface);
    border-radius: 2px;
    margin-top: 2px;
    opacity: 0.4;
}

/* Mejora: mejor espaciado de fórmulas en pantallas pequeñas */
@media (max-width: 480px) {
    .container { padding: 2rem 1rem 5rem; }
    .sec-title { font-size: 1.5rem; }
    .card-body { padding: 1rem; }
    .f-row { padding: 0.6rem 0.75rem; }
    header { padding: 3rem 1.5rem; }
    .theme-btn, .contact-btn { padding: 6px 12px; font-size: 0.75rem; gap: 6px; }
}

/* Mejora: respeta preferencia de movimiento reducido del sistema */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .header-bg, .sec-icon::after { animation: none !important; }
}

/* Mejora: impresión limpia */
@media print {
    nav, #btt, .theme-btn { display: none !important; }
    .section { display: block !important; }
    .card { opacity: 1 !important; transform: none !important; box-shadow: none !important; }
    body { background: white !important; color: black !important; }
}
