/**
 * ============================================================================
 * RELATANDO.COM — v11.6.0 · PAQUETE "SE SIENTE VIVO" (Awwwards)
 * ----------------------------------------------------------------------------
 * Efectos de percepción y retención, SIN librerías ni imágenes nuevas:
 *   1. Transiciones de vista (View Transitions API) al cambiar de tema y entre
 *      páginas.
 *   2. Apertura cinematográfica de la cabecera del relato (revelado enmascarado).
 *   3. Micro-interacciones: inclinación y luz que sigue al cursor en tarjetas.
 *   4. Índice del relato pegajoso con "estás aquí".
 *   5. Aviso "sigue leyendo" a mitad de relato y "continuar donde lo dejaste".
 *   6. Modo papel al imprimir.
 * Todo lo animado usa SOLO transform/opacity y se apaga con
 * prefers-reduced-motion. Nada se muestra sin JS (html.rel-js).
 * ============================================================================
 */

/* ---------------------------------------------------------------------------
   1. TRANSICIONES DE VISTA
   `navigation:auto` = fundido nativo entre páginas del mismo origen (Chrome/
   Edge 126+). En el resto de navegadores no pasa absolutamente nada.
   --------------------------------------------------------------------------- */
@view-transition {
    navigation: auto;
}

::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 0.24s;
    animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}

/* El cambio de tema (🕯️/🌑) también se funde: el JS envuelve el clic. */
html.rel-vt .rel-lectura-toolbar,
html.rel-vt .rel-grimorio {
    /* la barra no debe "viajar" en el fundido */
    view-transition-name: none;
}

/* ---------------------------------------------------------------------------
   2. APERTURA CINEMATOGRÁFICA
   --------------------------------------------------------------------------- */
@media (prefers-reduced-motion: no-preference) {
    .immersive-article .entry-header .entry-title {
        animation: rel-title-in 0.85s cubic-bezier(0.16, 1, 0.3, 1) 0.08s both;
    }

    .immersive-article .entry-header .entry-meta {
        animation: rel-meta-in 0.7s ease-out 0.34s both;
    }

    /* la foto abre con un zoom-out levísimo (solo transform) */
    .immersive-article .entry-header {
        animation: rel-hero-in 1.1s cubic-bezier(0.16, 1, 0.3, 1) both;
    }
}

@keyframes rel-title-in {
    from {
        opacity: 0;
        transform: translate3d(0, 14px, 0);
        clip-path: inset(0 0 100% 0);
    }

    to {
        opacity: 1;
        transform: none;
        clip-path: inset(0 0 0 0);
    }
}

@keyframes rel-meta-in {
    from {
        opacity: 0;
        transform: translate3d(0, 8px, 0);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes rel-hero-in {
    from {
        background-size: 106% auto;
    }

    to {
        background-size: 100% auto;
    }
}

/* ---------------------------------------------------------------------------
   3. MICRO-INTERACCIONES EN TARJETAS (inclinación + luz que sigue al cursor)
   El JS escribe --rx/--ry/--mx/--my. Sin JS o sin puntero fino, nada cambia.
   --------------------------------------------------------------------------- */
@media (hover: hover) and (prefers-reduced-motion: no-preference) {

    .rel-tilt,
    .rel-tilt * {
        transform-style: preserve-3d;
    }

    .rel-tilt {
        transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1),
            box-shadow 0.5s ease;
        will-change: transform;
    }

    .rel-tilt.is-tilting {
        transition: transform 0.08s linear, box-shadow 0.5s ease;
        transform: perspective(900px) rotateX(var(--ry, 0deg)) rotateY(var(--rx, 0deg)) translate3d(0, -4px, 0);
    }

    /* Luz que sigue al puntero: pseudoelemento (los pseudos NO los toca el
       modo papel del tema sepia, que solo afecta a elementos). */
    .rel-tilt::after {
        content: "";
        position: absolute;
        inset: 0;
        border-radius: inherit;
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.4s ease;
        background: radial-gradient(220px circle at var(--mx, 50%) var(--my, 50%),
            rgba(255, 255, 255, 0.14) 0%,
            rgba(255, 255, 255, 0.05) 38%,
            transparent 70%);
        z-index: 3;
    }

    .rel-tilt.is-tilting::after {
        opacity: 1;
    }

    html.rel-theme-sepia .rel-tilt::after {
        background: radial-gradient(220px circle at var(--mx, 50%) var(--my, 50%),
            rgba(139, 90, 19, 0.16) 0%,
            rgba(139, 90, 19, 0.06) 38%,
            transparent 70%);
    }
}

/* ---------------------------------------------------------------------------
   4. ÍNDICE DEL RELATO ("estás aquí")
   --------------------------------------------------------------------------- */
.rel-toc {
    margin: 0 0 2.2rem;
    border: 1px solid rgba(212, 175, 55, 0.28);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.02);
    overflow: hidden;
}

.rel-toc-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: 0;
    color: var(--color-gold, #d4af37);
    font: 700 0.82rem/1.2 Cinzel, serif;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
}

.rel-toc-head:hover,
.rel-toc-head:focus-visible {
    color: #fff;
}

.rel-toc[data-open="false"] .rel-toc-list {
    display: none;
}

.rel-toc-list {
    list-style: none;
    margin: 0;
    padding: 4px 10px 12px;
    counter-reset: reltoc;
}

.rel-toc-list li {
    margin: 0;
}

.rel-toc-list a {
    display: block;
    padding: 7px 10px;
    border-left: 2px solid transparent;
    border-radius: 0 8px 8px 0;
    color: inherit;
    opacity: 0.74;
    text-decoration: none;
    font-size: 0.92rem;
    line-height: 1.35;
    transition: opacity 0.25s ease, border-color 0.25s ease, background-color 0.25s ease;
}

.rel-toc-list li.is-h3 a {
    padding-left: 26px;
    font-size: 0.86rem;
    opacity: 0.6;
}

.rel-toc-list a:hover,
.rel-toc-list a:focus-visible {
    opacity: 1;
    border-left-color: var(--color-accent, #00ff88);
    background: rgba(255, 255, 255, 0.04);
}

.rel-toc-list a[aria-current="true"] {
    opacity: 1;
    font-weight: 700;
    border-left-color: var(--color-gold, #d4af37);
    background: rgba(212, 175, 55, 0.09);
}

/* La barra de progreso del índice: cuánto llevas de ESTE relato */
.rel-toc-progress {
    height: 3px;
    background: linear-gradient(90deg, var(--color-accent, #00ff88), var(--color-gold, #d4af37));
    transform-origin: left center;
    transform: scaleX(var(--rel-toc-p, 0));
}

/* En pantallas grandes el índice acompaña la lectura.
   v11.6.3 — TRES ARREGLOS:
   (1) `top` ya no es un número fijo (118px quedaba justo DEBAJO del menú, que
       mide ~113px y además se convierte en burbuja al desplazar). Ahora lo
       calcula el JS con la altura REAL de la cabecera + un hueco de respiro, y
       lo publica en la variable --rel-toc-top.
   (2) `left: calc(50% - 46rem)` se salía de la pantalla en monitores normales
       (1440px → -16px, 1366px → -53px). Ahora `left: max(12px, ...)`: nunca
       negativo.
   (3) Si el índice no cabe entero en el margen (portátiles de 1024-1300px) se
       recoge a una PASTILLA "📜 Índice" pegada al borde izquierdo y se despliega
       al pasar el ratón o al enfocarla: siempre a mano, nunca encima del texto. */
@media (min-width: 1024px) {
    .rel-toc-fixed {
        position: fixed;
        top: var(--rel-toc-top, 132px);
        left: max(12px, calc(50% - 46rem));
        right: auto;
        width: 15.5rem;
        margin: 0;
        z-index: 60;
        background: rgba(6, 15, 9, 0.84);
        -webkit-backdrop-filter: blur(8px) saturate(140%);
        backdrop-filter: blur(8px) saturate(140%);
        border-color: rgba(212, 175, 55, 0.34);
        box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
        max-height: calc(100vh - var(--rel-toc-top, 132px) - 26px);
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        transition: width 0.22s ease, opacity 0.22s ease;
    }

    .rel-toc-fixed .rel-toc-head {
        padding: 10px 12px;
    }

    .rel-toc-fixed .rel-toc-list a {
        padding: 6px 8px;
    }

    /* La pastilla: sólo el título, pegada al borde */
    .rel-toc-fixed.is-collapsed {
        width: auto;
        min-width: 0;
    }

    .rel-toc-fixed.is-collapsed .rel-toc-title {
        white-space: nowrap;
    }

    .rel-toc-fixed.is-collapsed .rel-toc-count,
    .rel-toc-fixed.is-collapsed .rel-toc-list {
        display: none;
    }

    .rel-toc-fixed.is-collapsed .rel-toc-head {
        justify-content: center;
        gap: 4px;
        padding: 9px 11px;
    }

    /* …y se despliega al acercarse (ratón o teclado) sin tocar el botón */
    .rel-toc-fixed.is-collapsed:hover,
    .rel-toc-fixed.is-collapsed:focus-within {
        width: 15.5rem;
    }

    .rel-toc-fixed.is-collapsed:hover .rel-toc-count,
    .rel-toc-fixed.is-collapsed:focus-within .rel-toc-count {
        display: inline;
    }

    .rel-toc-fixed.is-collapsed:hover .rel-toc-list,
    .rel-toc-fixed.is-collapsed:focus-within .rel-toc-list {
        display: block;
    }
}

@media (prefers-reduced-motion: reduce) {
    .rel-toc-fixed {
        transition: none;
    }
}

/* ---------------------------------------------------------------------------
   5. "SIGUE LEYENDO" + "CONTINUAR DONDE LO DEJASTE"
   --------------------------------------------------------------------------- */
.rel-next {
    position: fixed;
    left: 14px;
    /* v11.6.4: se sube para que no lo tape el banner de consentimiento de
       cookies, que ocupa la franja inferior de la pantalla. */
    bottom: 92px;
    width: min(22rem, calc(100vw - 28px));
    z-index: 48;
    padding: 12px 14px 10px;
    border-radius: 14px;
    background: rgba(6, 15, 9, 0.93);
    border: 1px solid rgba(212, 175, 55, 0.35);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55);
    color: #e6ede9;
    opacity: 0;
    transform: translate3d(0, 18px, 0);
    pointer-events: none;
    transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.rel-next.is-on {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.rel-next-title {
    margin: 0 0 8px;
    font: 700 0.7rem/1.2 Cinzel, serif;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: #d4af37;
}

.rel-next-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rel-next-list a {
    display: flex;
    gap: 8px;
    align-items: baseline;
    color: #e6ede9;
    font-size: 0.86rem;
    line-height: 1.3;
    text-decoration: none;
}

.rel-next-list a:hover,
.rel-next-list a:focus-visible {
    color: #00ff88;
}

.rel-next-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: 0;
    color: #8fa89b;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 4px;
}

.rel-next-resume {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid rgba(0, 255, 136, 0.4);
    background: rgba(0, 255, 136, 0.08);
    color: #e6ede9;
    font: 600 0.86rem/1.2 inherit;
    cursor: pointer;
    text-align: left;
}

.rel-next-resume:hover,
.rel-next-resume:focus-visible {
    background: rgba(0, 255, 136, 0.16);
}

html.rel-theme-sepia .rel-next {
    background: #f6edda;
    border-color: rgba(139, 90, 19, 0.35);
    color: #2b2118;
    box-shadow: 0 14px 34px rgba(90, 60, 20, 0.25);
}

html.rel-theme-sepia .rel-next-title {
    color: #8a5a13;
}

html.rel-theme-sepia .rel-next-list a,
html.rel-theme-sepia .rel-next-resume {
    color: #2b2118;
}

html.rel-theme-sepia .rel-next-resume {
    border-color: rgba(139, 90, 19, 0.4);
    background: rgba(139, 90, 19, 0.08);
}

html.rel-theme-sepia .rel-next-close {
    color: #7a6a52;
}

/* En móvil, por encima de la barra flotante de lectura */
@media (max-width: 767px) {
    .rel-next {
        left: 10px;
        bottom: 78px;
        width: calc(100vw - 20px);
    }
}

/* ---------------------------------------------------------------------------
   6. SONIDO AMBIENTE Y COMPARTIR EN LA BARRA DE LECTURA
   --------------------------------------------------------------------------- */
.rel-lt-btn[data-rel-amb][aria-pressed="true"] {
    background: rgba(0, 255, 136, 0.16);
    border-color: rgba(0, 255, 136, 0.5);
}

html.rel-theme-sepia .rel-lt-btn[data-rel-amb][aria-pressed="true"] {
    background: rgba(139, 90, 19, 0.2) !important;
    border-color: rgba(139, 90, 19, 0.55) !important;
}

/* ---------------------------------------------------------------------------
   7. BÚSQUEDA INSTANTÁNEA (404) Y ESTADOS VACÍOS
   --------------------------------------------------------------------------- */
.rel-live {
    margin: 14px 0 0;
    padding: 0;
    list-style: none;
    max-width: 640px;
}

.rel-live li {
    margin: 0 0 4px;
}

.rel-live a {
    display: block;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(212, 175, 55, 0.22);
    background: rgba(255, 255, 255, 0.02);
    text-decoration: none;
    color: inherit;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.rel-live a:hover,
.rel-live a:focus-visible {
    border-color: rgba(0, 255, 136, 0.45);
    background: rgba(0, 255, 136, 0.07);
}

.rel-live b {
    display: block;
    font-size: 0.95rem;
}

.rel-live span {
    font-size: 0.78rem;
    opacity: 0.62;
}

.rel-live-hint {
    font-size: 0.82rem;
    opacity: 0.7;
    margin-top: 8px;
}

/* ---------------------------------------------------------------------------
   8. FOCO VISIBLE COHERENTE EN TODO EL SITIO
   --------------------------------------------------------------------------- */
:focus-visible {
    outline: 2px solid var(--color-accent, #00ff88);
    outline-offset: 3px;
    border-radius: 4px;
}

html.rel-theme-sepia :focus-visible {
    outline-color: #8a5a13;
}

.rel-toc :focus-visible,
.rel-next :focus-visible {
    outline-offset: 2px;
}

/* ---------------------------------------------------------------------------
   9. SEPIA: huecos de anuncios y bloques vacíos en tono papel
   (especificidad 0,4,x: empata con el modo papel del módulo de lectura y, al
   ir después, gana)
   --------------------------------------------------------------------------- */
html.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia body .relatando-ad-slot,
html.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia body .relatando-ad-slot:empty {
    background: rgba(139, 90, 19, 0.05) !important;
    background-image: none !important;
    border-color: rgba(139, 90, 19, 0.26) !important;
    color: #6b4a12 !important;
}

/* ---------------------------------------------------------------------------
   9b. ÍNDICE EN MODO PAPEL (v11.6.3)
   El índice flotante llevaba fondo oscuro siempre: sobre papel quedaba como un
   agujero negro. Aquí pasa a tarjeta de papel con tinta marrón y oro viejo.
   --------------------------------------------------------------------------- */
html.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia body .rel-toc,
html.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia body .rel-toc-fixed {
    background: rgba(250, 243, 229, 0.97) !important;
    background-image: none !important;
    border-color: rgba(120, 76, 12, 0.42) !important;
    box-shadow: 0 12px 32px rgba(60, 36, 8, 0.2) !important;
    color: #3a2c1b !important;
    -webkit-backdrop-filter: blur(6px) saturate(1.05) !important;
    backdrop-filter: blur(6px) saturate(1.05) !important;
}

html.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia body .rel-toc-head {
    color: #6d460c !important;
}

html.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia body .rel-toc-head:hover,
html.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia body .rel-toc-head:focus-visible {
    color: #33240a !important;
}

html.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia body .rel-toc-list a {
    color: #4f3509 !important;
    opacity: 0.9;
}

html.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia body .rel-toc-list li.is-h3 a {
    color: #5c400f !important;
    opacity: 0.85;
}

html.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia body .rel-toc-list a:hover,
html.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia body .rel-toc-list a:focus-visible {
    background: rgba(139, 90, 19, 0.1) !important;
    border-left-color: #8a5a13 !important;
}

html.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia.rel-theme-sepia body .rel-toc-list a[aria-current="true"] {
    background: rgba(139, 90, 19, 0.16) !important;
    border-left-color: #8a5a13 !important;
    color: #2b1d05 !important;
}

/* Puente de tamaños de letra: el panel "Aa" (body.rel-fontplus-N) y la barra
   (--rel-fs) pasan a compartir la MISMA variable. Ver js del módulo. */
html.rel-fs-custom body[class*="rel-fontplus-"] .entry-content {
    font-size: calc(1.16rem * var(--rel-fs, 1)) !important;
}

@media (max-width: 767px) {
    html.rel-fs-custom body[class*="rel-fontplus-"] .entry-content {
        font-size: calc(1.05rem * var(--rel-fs, 1)) !important;
    }
}

/* ---------------------------------------------------------------------------
   10. IMPRIMIR EL RELATO (modo papel, sin adornos)
   --------------------------------------------------------------------------- */
@media print {
    .rel-lectura-toolbar,
    .rel-grimorio,
    .rel-next,
    .rel-toc,
    .relatando-ad-slot,
    .reading-progress,
    .fog-container,
    .fog-img,
    .global-glass-header,
    .crypt-minimal-command-bar,
    .site-header,
    .site-footer,
    .relatando-feedback,
    .rel-micro-feedback,
    .vault-lock-screen,
    .vip-locked-preview {
        display: none !important;
    }

    html,
    body {
        background: #fff !important;
        color: #1a1a1a !important;
    }

    .entry-content,
    .entry-content p,
    .entry-content li,
    .entry-content h2,
    .entry-content h3,
    .entry-content h4,
    .entry-content blockquote,
    .entry-header .entry-title,
    .entry-header .entry-meta {
        color: #1a1a1a !important;
        -webkit-text-fill-color: #1a1a1a !important;
        text-shadow: none !important;
        opacity: 1 !important;
        transform: none !important;
    }

    .entry-content a {
        color: #6b4a12 !important;
        text-decoration: underline;
    }

    .entry-header {
        min-height: 0 !important;
        padding: 0 0 12px !important;
        background-image: none !important;
    }

    .entry-header .header-overlay {
        display: none !important;
    }

    .immersive-article .entry-content::after {
        content: "relatando.com — relatos de terror y paranormal";
        display: block;
        margin-top: 18px;
        font-size: 0.75rem;
        color: #6b4a12;
    }
}
