/* La biblioteca de Aprender: el estante con las portadas y el libro abierto con hojas que se pasan (scripts/libro-hojas.js). */

/* ---------- El estante ---------- */
.estante {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr));
    gap: 1.8rem 1.2rem;
    margin: 0;
    padding: 0.4rem 0 0;
    list-style: none;
}

.libro-tarjeta {
    display: grid;
    gap: 0.7rem;
    align-content: start;
}

/* La portada: un libro de pie, con el lomo a la izquierda y el color propio de cada título */
.libro-portada {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.6rem;
    aspect-ratio: 3 / 4;
    padding: 1rem 0.9rem 0.8rem 1.3rem;
    overflow: hidden;
    color: #f4ecd8;
    font: inherit;
    text-align: left;
    background:
        linear-gradient(115deg, rgb(255 255 255 / 0.1), transparent 38%),
        linear-gradient(145deg, hsl(var(--tono, 152) 34% 29%), hsl(var(--tono, 152) 40% 13%));
    border: 0;
    border-radius: 3px 10px 10px 3px;
    box-shadow: inset 5px 0 0 rgb(0 0 0 / 0.3), inset 6px 0 0 rgb(255 255 255 / 0.08), 0 14px 24px -14px rgb(0 0 0 / 0.85);
    cursor: pointer;
    transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.libro-portada:hover,
.libro-portada:focus-visible {
    transform: translateY(-5px);
    box-shadow: inset 5px 0 0 rgb(0 0 0 / 0.3), inset 6px 0 0 rgb(255 255 255 / 0.08), 0 22px 28px -14px rgb(0 0 0 / 0.9);
}

.libro-portada:focus-visible {
    outline: 2px solid var(--activo-fondo);
    outline-offset: 3px;
}

.libro-portada.con-aviso {
    padding-top: 2.4rem;
}

.libro-portada-autor {
    font-size: 0.66rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    opacity: 0.72;
}

.libro-portada-titulo {
    margin: auto 0;
    font-family: var(--fuente-titulo);
    font-size: 1.12rem;
    font-weight: 600;
    line-height: 1.22;
    text-wrap: balance;
}

.libro-portada-pie {
    display: grid;
    gap: 0.35rem;
    font-size: 0.7rem;
    opacity: 0.85;
}

.libro-avance {
    height: 3px;
    background: rgb(255 255 255 / 0.18);
    border-radius: 3px;
}

.libro-avance span {
    display: block;
    height: 100%;
    background: #d9b86c;
    border-radius: inherit;
}

/* «Solo en inglés»: la traducción de ese libro no se pudo leer, y se remarca para que no sorprenda */
.libro-aviso {
    position: absolute;
    top: 0.75rem;
    left: 1.3rem;
    padding: 0.2rem 0.55rem;
    color: #2a1b00;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    background: #e8ad45;
    border-radius: 999px;
}

.libro-acciones {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.35rem;
}

/* Las píldoras (botones redondos de vidrio): el filtro del estante y los botones de cada libro */
.pildora {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 1.9rem;
    padding: 0 0.8rem;
    color: var(--texto);
    font: inherit;
    font-family: var(--fuente-texto);
    font-size: 0.74rem;
    font-weight: 500;
    white-space: nowrap;
    background: var(--boton-vidrio);
    border: 1px solid var(--vidrio-borde);
    border-radius: 999px;
    -webkit-backdrop-filter: blur(var(--vidrio-desenfoque));
    backdrop-filter: blur(var(--vidrio-desenfoque));
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.15s ease, color 0.15s ease;
}

.pildora:hover,
.pildora:focus-visible {
    background: var(--boton-vidrio-hover);
}

.pildora:disabled {
    cursor: default;
    opacity: 0.55;
}

.pildora:active {
    transform: scale(0.96);
}

.pildora.filtro {
    height: 2.1rem;
    padding: 0 1rem;
    font-size: 0.82rem;
}

.pildora[aria-pressed="true"] {
    color: var(--activo-texto);
    background: var(--activo-fondo);
    border-color: transparent;
}

.pildora.confirmar {
    color: var(--alta);
    border-color: var(--alta);
}

.libro-filtros {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.4rem 0 0.2rem;
}

.libro-cuenta {
    margin: 0.2rem 0 0;
    font-family: var(--fuente-texto);
    font-size: 0.8rem;
    opacity: 0.65;
}

/* ---------- El libro abierto ---------- */
.libro-dialogo {
    width: min(46rem, calc(100vw - 1rem));
    max-height: calc(100vh - 1rem);
    margin: auto;
    padding: 1rem 1.2rem 1.3rem;
    overflow: visible; /* la hoja que se dobla se sale un poco del libro: no debe crear barras de desplazamiento */
    color: var(--texto);
    background-color: color-mix(in srgb, var(--fondo) 90%, transparent);
    background-image: linear-gradient(115deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.04) 30%, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, 0.07) 100%);
    -webkit-backdrop-filter: blur(calc(var(--vidrio-desenfoque) * 3)) saturate(1.6);
    backdrop-filter: blur(calc(var(--vidrio-desenfoque) * 3)) saturate(1.6);
    border: 1px solid var(--vidrio-borde);
    border-radius: 22px;
    box-shadow: var(--brillo-panel), 0 30px 70px -24px rgba(0, 0, 0, 0.75);
}

.libro-dialogo::backdrop {
    background: rgb(0 0 0 / 0.72);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.libro-cabecera {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 1.1rem;
}

.libro-titulos {
    flex: 1;
    min-width: 0;
}

.libro-titulos h2 {
    margin: 0;
    overflow: hidden;
    font-size: 1.05rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.libro-titulos p {
    margin: 0.15rem 0 0;
    font-family: var(--fuente-texto);
    font-size: 0.8rem;
    opacity: 0.65;
}

.libro-estado {
    margin: 0;
    padding: 3.5rem 0;
    text-align: center;
    opacity: 0.7;
}

/* ---------- Las hojas ---------- */
.hojas {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 42rem;
    margin-inline: auto;
    overflow-x: clip;
}

.hojas-faja {
    flex-shrink: 0;
    width: 100%;
    border-radius: 4px;
    transition: transform 0.5s cubic-bezier(0.32, 0.72, 0, 1);
}

.hojas-faja-una {
    align-self: flex-start;
    width: 200%;
    transition: none;
}

.hojas-libro {
    position: relative;
    aspect-ratio: 3 / 2;
    width: 100%;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.hoja {
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    overflow: hidden;
    container-type: inline-size;
    color: var(--texto);
    background: color-mix(in srgb, var(--fondo) 92%, var(--texto));
    transform-origin: top left;
}

.hoja-izq {
    left: 0;
    border-radius: 6px 0 0 6px;
    box-shadow: inset -1px 0 0 rgb(0 0 0 / 0.22), 0 0 0 1px rgb(255 255 255 / 0.07);
}

.hoja-der {
    left: 50%;
    border-radius: 0 6px 6px 0;
    box-shadow: inset 1px 0 0 rgb(0 0 0 / 0.22), 0 0 0 1px rgb(255 255 255 / 0.07);
}

/* El reverso de una hoja es un tono más oscuro: así el doblez se lee como papel */
.hoja-reverso {
    background: color-mix(in srgb, var(--fondo) 84%, var(--texto));
}

.hoja-interior {
    width: 100%;
    height: 100%;
}

.hoja-reverso .hoja-interior {
    transform: scaleX(-1); /* el reverso se lee al derecho una vez doblado */
}

.hoja-lomo {
    position: absolute;
    inset-block: 0;
    width: 8%;
    pointer-events: none;
}

.hoja-izq .hoja-lomo {
    right: 0;
    background: linear-gradient(to left, rgb(0 0 0 / 0.3), transparent);
}

.hoja-der .hoja-lomo {
    left: 0;
    background: linear-gradient(to right, rgb(0 0 0 / 0.3), transparent);
}

.hojas-sombra {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* Lo de adentro se mide en cqw (1 % del ancho de la hoja): la hoja entera crece o se achica sin que el texto se acomode distinto */
.hoja-texto {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 8cqw 9cqw 6cqw;
}

.hoja-cabecera {
    margin: 0;
    overflow: hidden;
    font-family: var(--fuente-texto);
    font-size: 2.5cqw;
    letter-spacing: 0.2em;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
    opacity: 0.5;
}

.hoja-filete {
    display: block;
    width: 10cqw;
    height: 1px;
    margin: 3cqw 0 5cqw;
    background: var(--activo-fondo);
    opacity: 0.55;
}

.hoja-parrafo {
    flex: 1;
    margin: 0;
    overflow: hidden;
    font-family: var(--fuente-texto);
    font-size: 3.9cqw;
    line-height: 1.62;
    text-wrap: pretty;
}

.hoja-numero {
    margin: 2cqw 0 0;
    font-family: var(--fuente-texto);
    font-size: 2.7cqw;
    text-align: center;
    opacity: 0.45;
    font-variant-numeric: tabular-nums;
}

.hoja-portada {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 10cqw;
    color: #f4ecd8;
    text-align: center;
    background:
        linear-gradient(115deg, rgb(255 255 255 / 0.1), transparent 40%),
        linear-gradient(145deg, hsl(var(--tono, 152) 34% 29%), hsl(var(--tono, 152) 40% 13%));
}

.hoja-portada-titulo {
    margin: 0;
    font-family: var(--fuente-titulo);
    font-size: 7.5cqw;
    font-weight: 600;
    line-height: 1.15;
    text-wrap: balance;
}

.hoja-portada-filete {
    display: block;
    width: 14cqw;
    height: 1px;
    margin: 5cqw 0;
    background: #d9b86c;
}

.hoja-portada-autor {
    margin: 0;
    font-family: var(--fuente-texto);
    font-size: 3.2cqw;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    opacity: 0.78;
}

.hoja-portada-aviso {
    margin: 6cqw 0 0;
    padding: 1cqw 3.2cqw;
    color: #2a1b00;
    font-family: var(--fuente-texto);
    font-size: 2.7cqw;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    background: #e8ad45;
    border-radius: 999px;
}

.hoja-portada-pista {
    position: absolute;
    bottom: 7cqw;
    margin: 0;
    font-family: var(--fuente-texto);
    font-size: 2.8cqw;
    opacity: 0.55;
}

.hojas-nav {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    margin-top: 1.2rem;
    font-family: var(--fuente-texto);
    font-size: 0.82rem;
}

.hojas-cuenta {
    min-width: 9rem;
    text-align: center;
    font-variant-numeric: tabular-nums;
    opacity: 0.75;
}

.hojas-flecha {
    display: grid;
    place-items: center;
    width: 2.3rem;
    height: 2.3rem;
    color: var(--texto);
    background: var(--boton-vidrio);
    border: 1px solid var(--vidrio-borde);
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.hojas-flecha:hover,
.hojas-flecha:focus-visible {
    background: var(--boton-vidrio-hover);
}

.hojas-flecha svg {
    width: 1rem;
    height: 1rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.hojas-flecha[aria-disabled="true"] {
    opacity: 0.35;
    cursor: default;
}

@media (prefers-reduced-motion: reduce) {
    .hojas-faja,
    .libro-portada {
        transition: none;
    }
}
