html, body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* La paleta esta en tokens.css y el fondo animado en base.css; las dos las
   carga head_base.html ANTES que esta hoja. */
html {
    position: relative;
}

body {
    font-family: 'Nunito Sans', sans-serif;
    font-synthesis-weight: auto;
    color: var(--text-primary);
    background-color: var(--bg-1);
    background-image:
        radial-gradient(ellipse at 50% 46%, rgba(168, 120, 255, 0.34), transparent 56%),
        radial-gradient(circle at 8% 26%, rgba(92, 141, 255, 0.66), transparent 41%),
        radial-gradient(circle at 84% 24%, rgba(230, 96, 255, 0.58), transparent 43%),
        radial-gradient(circle at 42% 72%, rgba(96, 210, 255, 0.3), transparent 40%),
        radial-gradient(circle at 16% 14%, rgba(255, 255, 255, 0.46) 0 1px, transparent 2px),
        radial-gradient(circle at 74% 68%, rgba(255, 255, 255, 0.34) 0 1px, transparent 2px),
        radial-gradient(circle at 36% 58%, rgba(255, 255, 255, 0.28) 0 1px, transparent 2px),
        radial-gradient(circle at 68% 34%, rgba(255, 255, 255, 0.32) 0 1px, transparent 2px),
        radial-gradient(circle at 22% 62%, rgba(255, 255, 255, 0.22) 0 1px, transparent 2px),
        radial-gradient(circle at 90% 78%, rgba(255, 255, 255, 0.2) 0 1px, transparent 2px),
        linear-gradient(140deg, var(--bg-1) 0%, var(--bg-2) 52%, var(--bg-3) 100%);
    background-blend-mode: screen, screen, screen, screen, screen, screen, screen, screen, screen, screen, normal;
    background-repeat: no-repeat;
    background-size: 130% 130%, 125% 125%, 140% 140%, 130% 130%, 420px 420px, 560px 560px, 620px 620px, 760px 760px, 840px 840px, 980px 980px, 100% 100%;
    background-position: center center;
    min-height: 100vh;
    position: relative;
    isolation: isolate;
    overflow-x: hidden;
}

body::before {
    background:
        radial-gradient(circle at 12% 20%, rgba(140, 188, 255, 0.42), transparent 24%),
        radial-gradient(circle at 82% 18%, rgba(239, 122, 255, 0.46), transparent 27%),
        radial-gradient(circle at 58% 82%, rgba(131, 110, 255, 0.36), transparent 24%);
    filter: blur(30px);
    mix-blend-mode: screen;
    animation: nebulaDrift 22s ease-in-out infinite alternate;
}

body::after {
    background:
        radial-gradient(circle at 18% 26%, rgba(255, 255, 255, 0.82) 0 1px, transparent 2px),
        radial-gradient(circle at 62% 32%, rgba(255, 255, 255, 0.72) 0 1px, transparent 2px),
        radial-gradient(circle at 74% 72%, rgba(255, 255, 255, 0.7) 0 1px, transparent 2px),
        radial-gradient(circle at 38% 80%, rgba(255, 255, 255, 0.6) 0 1px, transparent 2px),
        radial-gradient(circle at 52% 44%, rgba(255, 255, 255, 0.56) 0 1px, transparent 2px);
    background-size: 280px 280px, 380px 380px, 480px 480px, 560px 560px, 700px 700px;
    opacity: 0.58;
    inset: -8%;
    will-change: transform, opacity;
    animation: starDrift 70s ease-in-out infinite alternate, starTwinkle 14s ease-in-out infinite alternate;
}

body.has-header {
    padding-top: 20px;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: #ffffff;
}

.book-scroll-top-btn {
    position: fixed;
    bottom: calc(132px + var(--tabbar-inset, 0px));
    right: 20px;
    width: 48px;
    height: 48px;
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-sm);
    background: var(--fab-bg);
    border: 1px solid var(--glass-border);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-primary);
    z-index: 1000;
    transition: transform 0.2s ease, background 0.2s ease;
}

.book-scroll-top-btn:hover {
    transform: scale(1.08);
    background: var(--fab-bg-hover);
}

.book-scroll-top-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0);
}

::-webkit-scrollbar-thumb {
    background-color: rgba(163, 181, 212, 0.52);
    border-radius: var(--radius-lg);
}

.modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    padding: 16px;
    background-color: rgba(1, 8, 16, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
}

.modal.modal-open {
    animation: modalFadeIn 0.22s ease-out;
}

.close {
    color: var(--text-secondary);
    position: absolute;
    right: 10px;
    top: 10px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid rgba(198, 214, 242, 0.26);
    background: rgba(8, 16, 34, 0.78);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    z-index: 2;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.close:hover {
    color: #fff;
    background: rgba(18, 32, 62, 0.92);
    border-color: rgba(216, 228, 248, 0.46);
}

.close::before,
.close::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
}

.close::before {
    transform: rotate(45deg);
}

.close::after {
    transform: rotate(-45deg);
}

@media (max-width: 767px) {
    /* Centrado y no estirado: la ficha mide lo que su contenido y solo llega
       al alto de la pantalla si lo necesita. Estirada, una serie con dos líneas
       de sinopsis dejaba media pantalla de ficha vacía. */
    .modal {
        padding: 8px;
        align-items: center;
    }
}

.stars {
    color: #f0d496;
    text-shadow: 0 0 8px rgba(240, 212, 150, 0.35);
}

.rating-stars {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    color: #f0d496;
    font-size: 1.05em;
    line-height: 1;
    text-shadow: 0 0 8px rgba(240, 212, 150, 0.35);
}

.rating-star {
    position: relative;
    display: inline-block;
}

.rating-star-empty,
.rating-star-half {
    color: rgba(240, 212, 150, 0.28);
    text-shadow: none;
}

.rating-star-half::before {
    content: '★';
    position: absolute;
    inset: 0;
    width: 50%;
    overflow: hidden;
    color: #f0d496;
    text-shadow: 0 0 8px rgba(240, 212, 150, 0.35);
}

@media (min-width: 1024px) {
    .modal {
        background-color: rgba(2, 10, 20, 0.72);
        -webkit-backdrop-filter: blur(10px) saturate(120%);
        backdrop-filter: blur(10px) saturate(120%);
    }
}

.feed-loader-pill {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 9px 20px 9px 15px;
    border-radius: var(--radius-pill);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    backdrop-filter: blur(12px) saturate(140%);
    box-shadow: var(--shadow-md);
    color: var(--text-secondary);
    font-family: 'Nunito Sans', sans-serif;
    font-size: 0.88rem;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.feed-loader-orbit {
    position: relative;
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid rgba(198, 214, 242, 0.22);
    animation: orbitSpin 1.5s linear infinite;
}

/* Núcleo: centrado, así que gira con el padre sin que se note. */
.feed-loader-orbit::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    margin: -2.5px 0 0 -2.5px;
    border-radius: 50%;
    background: rgba(198, 214, 242, 0.5);
}

/* Satélite */
.feed-loader-orbit::after {
    content: '';
    position: absolute;
    top: -3.5px;
    left: 50%;
    width: 7px;
    height: 7px;
    margin-left: -3.5px;
    border-radius: 50%;
    background: var(--accent-strong);
    box-shadow: 0 0 10px rgba(143, 180, 232, 0.85);
}

.feed-loader-text {
    animation: loaderPulse 1.8s ease-in-out infinite;
}

/* Con movimiento reducido no gira nada: la órbita solo respira. */
@media (prefers-reduced-motion: reduce) {
    .feed-loader-orbit {
        animation: loaderPulse 2.4s ease-in-out infinite;
    }

    .feed-loader-text {
        animation: none;
    }
}

/* Modo rendimiento para móvil / dispositivos modestos */
@media (max-width: 900px), (prefers-reduced-motion: reduce) {
    body {
        background-color: var(--bg-1) !important;
        background-image:
            radial-gradient(circle at 14% 18%, rgba(92, 141, 255, 0.32), transparent 34%),
            radial-gradient(circle at 82% 22%, rgba(230, 96, 255, 0.24), transparent 36%),
            radial-gradient(circle at 58% 78%, rgba(96, 210, 255, 0.18), transparent 32%),
            linear-gradient(140deg, var(--bg-1) 0%, var(--bg-2) 52%, var(--bg-3) 100%) !important;
        background-blend-mode: normal !important;
        background-size: 100% 100% !important;
        background-position: center center !important;
    }

    *,
    *::before,
    *::after {
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }

    .book-cover,
    .modal-content,
    .book-search-btn,
    .book-scroll-top-btn,
    .header {
        box-shadow: 0 2px 8px rgba(2, 8, 18, 0.24) !important;
    }

    /* Sin blur la pastilla se vería translúcida: se opaca, como el header. */
    .feed-loader-pill {
        background: rgba(11, 20, 44, 0.92) !important;
        box-shadow: 0 4px 12px rgba(2, 8, 18, 0.26) !important;
    }
}

/* Insignias de contador: la de visitas en la cabecera y la de comentarios en
   la tarjeta de noticia. Eran la misma regla escrita dos veces, en header.css y
   en news.css, con un comentario en cada una pidiendo acordarse de cambiar la
   otra. Aqui van juntas porque styles.css lo cargan las dos paginas y va antes
   en la cascada, asi que cada hoja sigue pudiendo matizar lo suyo: el encogido
   en movil de la de visitas y la animacion de aparicion de la de comentarios.

   Azul del sitio y no rojo, a proposito: adelantan un dato para no entrar en
   balde, no avisan de nada urgente. */
.visits-badge,
.comments-badge {
    position: absolute;
    top: -7px;
    right: -7px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    box-sizing: border-box;
    border: 1px solid rgba(9, 16, 28, 0.85);
    border-radius: var(--radius-pill);
    background: var(--accent-strong);
    color: #06101f;
    /* 12 px, el mínimo legible de tokens.css: a 10 la cifra era un borrón. */
    font-size: var(--text-xs);
    font-weight: 700;
    line-height: 16px;
    letter-spacing: -0.02em;
    text-align: center;
    pointer-events: none;
    box-shadow: var(--shadow-sm);
}

@keyframes orbitSpin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes loaderPulse {
    0%, 100% {
        opacity: 0.58;
    }
    50% {
        opacity: 1;
    }
}

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

@keyframes nebulaDrift {
    from {
        transform: translate3d(-1.5%, -1%, 0) scale(1);
    }
    to {
        transform: translate3d(1.5%, 1%, 0) scale(1.06);
    }
}

@keyframes starTwinkle {
    from {
        opacity: 0.34;
    }
    to {
        opacity: 0.58;
    }
}
