/* ==========================================================================
   1. VARIABLES DEL SISTEMA DE DISEÑO (Tokens)
   Estética minimalista clara, neutra y de alto contraste para lectura técnica
   ========================================================================== */
:root {
    /* Paleta de colores */
    --bg-primary: #FAFAFA;         /* Fondo general gris alabastro muy suave */
    --bg-surface: #FFFFFF;         /* Fondo de tarjetas, cabecera y contenedores */
    --bg-muted: #F3F4F6;           /* Fondo para código en línea, tags y citas */
    --bg-code-block: #0F172A;      /* Fondo oscuro profundo para bloques <pre> */
    
    --text-primary: #111827;       /* Texto principal casi negro para máxima legibilidad */
    --text-secondary: #374151;     /* Texto de párrafos largos */
    --text-muted: #6B7280;         /* Fechas, pies de figura y metadatos */
    --text-code-block: #F8FAFC;    /* Texto claro dentro de bloques de código */
    
    --accent: #2563EB;             /* Azul técnico sobrio para enlaces y detalles */
    --accent-hover: #1D4ED8;       /* Estado hover del acento */
    --accent-subtle: #EFF6FF;      /* Fondo suave para citas de diseño */
    
    --border-color: #E5E7EB;       /* Bordes sutiles de tarjetas y divisores */
    --border-hover: #CBD5E1;       /* Borde al pasar el cursor sobre tarjetas */
    
    /* Tipografía */
    --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    
    /* Dimensiones y espaciado */
    --container-max: 1040px;       /* Ancho máximo para el listado de tarjetas */
    --container-narrow: 720px;     /* Ancho óptimo de lectura para artículos (65-75 chars) */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 12px;
    
    /* Sombras y transiciones */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.06);
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   2. RESET Y BASE GLOBAL
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body.site-wrapper {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.7;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
    height: auto;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-hover);
}

/* ==========================================================================
   3. CONTENEDORES Y LAYOUT COMPARTIDO (base.html)
   ========================================================================== */
.container {
    width: 100%;
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 1.5rem;
}

.container-narrow {
    width: 100%;
    max-width: var(--container-narrow);
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* Cabecera superior */
.site-header {
    background-color: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-inner {
    height: 4rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand-logo {
    font-family: var(--font-mono);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.brand-logo:hover {
    color: var(--text-primary);
}

.brand-prompt {
    color: var(--accent);
    margin-right: 0.15rem;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 1.75rem;
}

.nav-link {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
}

.nav-link:hover {
    color: var(--accent);
}

/* Área principal y Pie de página */
.site-main {
    flex: 1;
    padding: 3.5rem 0 5rem;
}

.site-footer {
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    padding: 2rem 0;
    margin-top: auto;
}

.footer-inner {
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.footer-text {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ==========================================================================
   4. PÁGINA DE INICIO Y TARJETAS DE PUBLICACIONES (index.html)
   ========================================================================== */
.hero-section {
    max-width: 680px;
    margin-bottom: 3.5rem;
}

.hero-title {
    font-size: clamp(1.85rem, 3.5vw, 2.5rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.2;
    color: var(--text-primary);
    margin-bottom: 0.85rem;
}

.hero-subtitle {
    font-size: 1.1rem;
    color: var(--text-muted);
    line-height: 1.6;
}

/* Grilla responsiva de tarjetas */
.posts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    gap: 2rem;
}

.post-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.post-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-hover);
}

/* Imagen de portada en tarjeta con proporción fija 16:9 */
.card-image-link {
    display: block;
    overflow: hidden;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-muted);
}

.card-image-wrapper {
    aspect-ratio: 16 / 9;
    width: 100%;
    overflow: hidden;
}

.card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 300ms ease;
}

.post-card:hover .card-image {
    transform: scale(1.03);
}

.card-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.65rem;
    margin-bottom: 0.75rem;
}

.meta-date {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Lista de etiquetas (compartida entre tarjetas y vista de artículo) */
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    list-style: none;
}

.tag-item {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-secondary);
    background-color: var(--bg-muted);
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    border: 1px solid var(--border-color);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.35;
    letter-spacing: -0.015em;
    margin-bottom: 0.65rem;
}

.card-title-link {
    color: var(--text-primary);
}

.card-title-link:hover {
    color: var(--accent);
}

.card-summary {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
    flex: 1;
}

.card-footer {
    margin-top: auto;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border-color);
}

.read-more-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--accent);
}

.arrow-icon {
    transition: transform var(--transition-fast);
}

.read-more-link:hover .arrow-icon {
    transform: translateX(3px);
}

.empty-state {
    background-color: var(--bg-surface);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--text-muted);
}

/* ==========================================================================
   5. CABECERA Y ESTRUCTURA DEL ARTÍCULO INDIVIDUAL (post.html)
   ========================================================================== */
.post-header {
    margin-bottom: 2.5rem;
}

.post-back {
    margin-bottom: 1.75rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
}

.back-link:hover {
    color: var(--text-primary);
}

.post-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.meta-divider {
    color: var(--border-hover);
}

.post-title {
    font-size: clamp(1.9rem, 4vw, 2.65rem);
    font-weight: 800;
    line-height: 1.18;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.post-lead {
    font-size: 1.15rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 1.75rem;
}

.post-cover {
    margin-top: 1.75rem;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border-color);
    background-color: var(--bg-muted);
}

.post-cover-image {
    width: 100%;
    max-height: 440px;
    object-fit: cover;
}

.post-footer {
    margin-top: 4rem;
}

.post-divider {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin-bottom: 1.75rem;
}

/* ==========================================================================
   6. MOTOR DE CONTENIDO MARKDOWN (.prose)
   Estiliza automáticamente la estructura de plantilla_2.md
   ========================================================================== */
.prose {
    color: var(--text-secondary);
    font-size: 1.0625rem; /* 17px para lectura cómoda */
    line-height: 1.78;
}

/* Párrafos */
.prose p {
    margin-bottom: 1.35rem;
}

/* Encabezados H2, H3, H4 dentro del Markdown */
.prose h2 {
    color: var(--text-primary);
    font-size: 1.55rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.3;
    margin-top: 3rem;
    margin-bottom: 1rem;
    padding-bottom: 0.45rem;
    border-bottom: 1px solid var(--border-color);
}

.prose h3 {
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.35;
    margin-top: 2.25rem;
    margin-bottom: 0.75rem;
}

.prose h4 {
    color: var(--text-primary);
    font-size: 1.05rem;
    font-weight: 600;
    margin-top: 1.75rem;
    margin-bottom: 0.5rem;
}

/* Enlaces dentro del artículo */
.prose a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
    font-weight: 500;
}

.prose a:hover {
    color: var(--accent-hover);
    text-decoration-thickness: 2px;
}

/* Negritas y énfasis */
.prose strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Listas ordenadas y desordenadas */
.prose ul,
.prose ol {
    margin-top: 0.5rem;
    margin-bottom: 1.5rem;
    padding-left: 1.6rem;
}

.prose li {
    margin-bottom: 0.5rem;
    padding-left: 0.25rem;
}

.prose li > ul,
.prose li > ol {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

/* Imágenes del cuerpo y pies de figura (*Figura 1: ...* en plantilla_2.md) */
.prose img {
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-surface);
    margin: 2.25rem auto 0.6rem;
    box-shadow: var(--shadow-sm);
}

/* Detecta automáticamente el texto en cursiva debajo de la imagen en plantilla_2.md */
.prose img + em,
.prose img + br + em,
.prose p > em:only-child {
    display: block;
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 0.35rem;
    margin-bottom: 2rem;
    line-height: 1.45;
}

/* Citas y Notas de diseño (> **Nota de diseño:** en plantilla_2.md) */
.prose blockquote {
    background-color: var(--accent-subtle);
    border-left: 4px solid var(--accent);
    padding: 1.1rem 1.35rem;
    margin: 1.85rem 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-primary);
    font-size: 0.98rem;
}

.prose blockquote p:last-child {
    margin-bottom: 0;
}

/* Código en línea (`inline code`) */
.prose :not(pre) > code {
    font-family: var(--font-mono);
    font-size: 0.86em;
    color: var(--text-primary);
    background-color: var(--bg-muted);
    border: 1px solid var(--border-color);
    padding: 0.18em 0.42em;
    border-radius: 4px;
    word-break: break-word;
}

/* Bloques de código (<pre><code>) y botón de copiado */
.prose pre {
    position: relative;
    background-color: var(--bg-code-block);
    color: var(--text-code-block);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.65;
    padding: 1.25rem 1.5rem;
    margin: 1.75rem 0;
    border-radius: var(--radius-md);
    overflow-x: auto;
    border: 1px solid #1E293B;
    box-shadow: var(--shadow-sm);
}

.prose pre code {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: transparent;
    border: 0;
    padding: 0;
}

/* Botón "Copiar" que inyectará nuestro archivo main.js */
.copy-code-btn {
    position: absolute;
    top: 0.65rem;
    right: 0.65rem;
    background-color: rgba(255, 255, 255, 0.1);
    color: #CBD5E1;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-sm);
    padding: 0.25rem 0.6rem;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.copy-code-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: #FFFFFF;
}

.copy-code-btn.copied {
    background-color: #10B981;
    border-color: #10B981;
    color: #FFFFFF;
}

/* Tablas en Markdown */
.prose table {
    width: 100%;
    border-collapse: collapse;
    margin: 2rem 0;
    font-size: 0.925rem;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.prose th,
.prose td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.prose th {
    background-color: var(--bg-muted);
    color: var(--text-primary);
    font-weight: 600;
}

.prose tr:last-child td {
    border-bottom: 0;
}

/* Separadores horizontales (---) */
.prose hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 2.5rem 0;
}

/* ==========================================================================
   7. DISEÑO RESPONSIVE (Móviles y Tablets)
   ========================================================================== */
@media (max-width: 768px) {
    .site-main {
        padding: 2.25rem 0 3.5rem;
    }

    .hero-section {
        margin-bottom: 2.25rem;
    }

    .posts-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .prose {
        font-size: 1rem;
    }

    .prose h2 {
        font-size: 1.35rem;
        margin-top: 2.25rem;
    }

    .prose h3 {
        font-size: 1.15rem;
    }

    .prose pre {
        padding: 1rem;
        font-size: 0.825rem;
    }
}
/* ==========================================================================
   8. LANGUAGE SWITCHER (EN / ES / JA / ZH)
   ========================================================================== */
.lang-switcher-wrapper {
    display: flex;
    align-items: center;
}

.lang-select {
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--bg-muted);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.3rem 1.75rem 0.3rem 0.65rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.lang-select:hover,
.lang-select:focus {
    border-color: var(--accent);
    outline: none;
}
