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

*, *::before, *::after {
    box-sizing: inherit;
}

@font-face {
    font-family: 'Ubuntu';
    src: url('../fonts/ubuntu.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

:root {
    --bg-1: #070715;
    --bg-2: #131b46;
    --bg-3: #341b63;
    --text-primary: #f2f5fb;
    --text-secondary: rgba(227, 233, 245, 0.78);
    --glass-bg: rgba(11, 20, 44, 0.48);
    --glass-bg-soft: rgba(34, 30, 70, 0.3);
    --glass-border: rgba(207, 220, 241, 0.27);
    --glass-highlight: rgba(255, 255, 255, 0.15);
    --card-bg: rgba(255, 255, 255, 0.03);
    --card-border: rgba(198, 214, 242, 0.16);
    --card-hover: rgba(216, 228, 248, 0.46);
    --accent: #c6d6f5;
    --accent-strong: #8fb4e8;
    --accent-warm: #d6bc8f;
}

html {
    position: relative;
}

html::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -2;
    background:
        radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.78) 0 1px, transparent 2px),
        radial-gradient(circle at 26% 64%, rgba(207, 229, 255, 0.64) 0 1px, transparent 2px),
        radial-gradient(circle at 44% 36%, rgba(255, 255, 255, 0.72) 0 1px, transparent 2px),
        radial-gradient(circle at 58% 82%, rgba(210, 181, 255, 0.62) 0 1px, transparent 2px),
        radial-gradient(circle at 76% 28%, rgba(255, 255, 255, 0.7) 0 1px, transparent 2px),
        radial-gradient(circle at 88% 72%, rgba(194, 222, 255, 0.58) 0 1px, transparent 2px);
    background-size: 340px 340px, 460px 460px, 620px 620px, 760px 760px, 980px 980px, 1240px 1240px;
    opacity: 0.46;
    animation: starDrift 80s linear infinite, starTwinkleSlow 18s ease-in-out infinite alternate;
}

html::after {
    content: '';
    position: fixed;
    top: 12%;
    left: 78%;
    width: 180px;
    height: 2px;
    pointer-events: none;
    z-index: -1;
    opacity: 0;
    transform: rotate(-24deg) translate3d(0, 0, 0);
    transform-origin: right center;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(210, 232, 255, 0.98) 55%, rgba(255, 255, 255, 0.1));
    filter: drop-shadow(0 0 8px rgba(181, 214, 255, 0.86));
    animation: shootingStar 19s linear infinite;
}

body {
    font-family: 'Ubuntu', sans-serif;
    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,
body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
}

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;
    animation: starDrift 70s linear infinite, 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-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 0 auto;
    max-width: 1400px;
    padding: 0 20px;
    justify-items: center;
}

.book-item {
    width: 100%;
    max-width: 300px;
    height: 450px;
    margin: 0 auto;
}

.book-info-container {
    width: 100%;
    height: 100%;
    position: relative;
    text-align: center;
    transform-style: preserve-3d;
}

.book-cover,
.book-info {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.6s;
    border-radius: 12px;
}

.book-info p {
    margin: 5px 0;
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-cover {
    transform: rotateY(0deg);
    border: 1px solid var(--card-border);
    box-shadow: 0 12px 26px rgba(2, 8, 18, 0.45);
}

.book-cover img {
    max-width: 100%;
    max-height: 100%;
    border-radius: inherit;
    object-fit: cover;
    width: 100%;
    height: 100%;
}

.book-info {
    background: linear-gradient(155deg, var(--glass-highlight), var(--glass-bg-soft) 20%, var(--glass-bg) 75%);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    transform: rotateY(180deg);
    flex-direction: column;
    padding: 15px;
    overflow: hidden;
    backdrop-filter: blur(16px) saturate(120%);
    -webkit-backdrop-filter: blur(16px) saturate(120%);
}

.book-info a.book-title {
    font-size: 1.1em;
    margin-bottom: 10px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-cover:hover {
    cursor: pointer;
}

.book-search-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    box-shadow: 0 8px 20px rgba(3, 10, 20, 0.45);
    border-radius: 50%;
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.22), rgba(143, 180, 232, 0.86));
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #f2f5fb;
    z-index: 1000;
    transition: transform 0.2s ease, background 0.2s ease;
}

.book-scroll-top-btn {
    position: fixed;
    bottom: 76px;
    right: 20px;
    width: 48px;
    height: 48px;
    box-shadow: 0 8px 20px rgba(3, 10, 20, 0.45);
    border-radius: 50%;
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.22), rgba(143, 180, 232, 0.86));
    border: 1px solid var(--glass-border);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #f2f5fb;
    z-index: 1000;
    transition: transform 0.2s ease, background 0.2s ease;
}

.book-scroll-top-btn:hover {
    transform: scale(1.08);
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.3), rgba(143, 180, 232, 0.94));
}

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

.book-search-btn:hover {
    transform: scale(1.08);
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.3), rgba(143, 180, 232, 0.94));
}

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

.book-search-btn.is-clear {
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.24), rgba(214, 188, 143, 0.9));
}

.book-search-btn.is-clear:hover {
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.32), rgba(214, 188, 143, 0.98));
}

::-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: 20px;
}

.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-content {
    background: linear-gradient(150deg, rgba(238, 246, 255, 0.18), rgba(36, 54, 82, 0.52) 34%, rgba(11, 20, 38, 0.78) 78%);
    border: 1px solid rgba(218, 231, 250, 0.34);
    color: var(--text-primary);
    margin: 0;
    padding: 20px;
    border-radius: 14px;
    width: min(920px, 92vw);
    max-height: calc(100vh - 32px);
    box-shadow: 0 30px 64px rgba(2, 8, 18, 0.62), inset 0 1px 0 rgba(255, 255, 255, 0.24);
    position: relative;
    animation: zoomIn 0.3s ease-out;
    -webkit-backdrop-filter: blur(18px) saturate(130%);
    backdrop-filter: blur(18px) saturate(130%);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-content h2 {
    margin: 20px 0 10px;
    line-height: 1.15;
}

.modal-content p {
    margin: 8px 0;
    line-height: 1.35;
}

.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) {
    .modal-content {
        width: 94%;
        max-height: calc(100vh - 24px);
        padding: 16px 14px;
    }
}

@media (min-width: 1200px) {
    .book-container {
        grid-template-columns: repeat(6, 1fr);
    }

    .book-item {
        width: 200px;
        height: 300px;
    }

    .book-info a.book-title {
        font-size: 1.2em;
    }

    .book-info p {
        font-size: 1em;
    }
}

@media (max-width: 1199px) and (min-width: 992px) {
    .book-container {
        grid-template-columns: repeat(4, 1fr);
    }

    .book-item {
        width: 250px;
        height: 375px;
    }

    .book-info a.book-title {
        font-size: 1.1em;
    }

    .book-info p {
        font-size: 0.9em;
    }
}

@media (max-width: 991px) and (min-width: 768px) {
    .book-container {
        grid-template-columns: repeat(3, 1fr);
    }

    .book-item {
        width: 200px;
        height: 300px;
    }

    .book-info a.book-title {
        font-size: 1em;
    }

    .book-info p {
        font-size: 0.85em;
    }
}

@media (max-width: 767px) {
    .book-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
        padding: 0 15px;
    }

    .book-item {
        width: calc((100vw - 50px) / 2);
        height: calc(((100vw - 50px) / 2) * 1.5);
        max-width: 200px;
        max-height: 300px;
    }

    .book-info {
        padding: 10px;
    }

    .book-info a.book-title {
        font-size: 0.9em;
    }

    .book-info p {
        font-size: 0.8em;
        margin: 3px 0;
    }
}

@media (max-width: 479px) {
    .book-container {
        padding: 0 10px;
        gap: 10px;
    }

    .book-info {
        padding: 8px;
    }

    .book-info a.book-title {
        font-size: 0.8em;
    }

    .book-info p {
        font-size: 0.7em;
        margin: 2px 0;
    }
}

.book-description {
    text-align: justify;
    margin-top: 10px;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid rgba(198, 214, 242, 0.18);
    background: rgba(8, 14, 30, 0.62);
    -webkit-backdrop-filter: blur(6px) saturate(105%);
    backdrop-filter: blur(6px) saturate(105%);
    line-height: 1.55;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.books-search-content {
    width: min(560px, 92vw);
    max-height: none;
    overflow: visible;
    padding: 22px 20px 18px;
    background: linear-gradient(150deg, rgba(242, 248, 255, 0.22), rgba(42, 58, 84, 0.54) 38%, rgba(13, 22, 38, 0.78) 82%);
    border-color: rgba(220, 232, 250, 0.38);
    box-shadow: 0 34px 72px rgba(2, 8, 18, 0.64), inset 0 1px 0 rgba(255, 255, 255, 0.28);
    -webkit-backdrop-filter: blur(20px) saturate(132%);
    backdrop-filter: blur(20px) saturate(132%);
}

.books-search-content h2 {
    margin: 0 0 6px;
}

.books-search-subtitle {
    margin: 0 0 14px;
    color: var(--text-secondary);
}

.books-search-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.books-search-input {
    width: 100%;
    height: 44px;
    border-radius: 10px;
    border: 1px solid rgba(198, 214, 242, 0.34);
    background: rgba(8, 14, 30, 0.7);
    color: var(--text-primary);
    padding: 0 12px;
    font: inherit;
    outline: none;
}

.books-search-input:focus {
    border-color: var(--accent-strong);
    box-shadow: 0 0 0 2px rgba(143, 180, 232, 0.25);
}

.books-search-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.books-search-apply,
.books-search-cancel {
    height: 38px;
    min-width: 92px;
    border-radius: 9px;
    border: 1px solid rgba(198, 214, 242, 0.28);
    font: inherit;
    cursor: pointer;
    transition: transform 0.15s ease, background-color 0.2s ease, color 0.2s ease;
}

.books-search-apply {
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.22), rgba(143, 180, 232, 0.86));
    color: #06101f;
    font-weight: 700;
}

.books-search-cancel {
    background: rgba(8, 14, 30, 0.72);
    color: var(--text-primary);
}

.books-search-apply:hover,
.books-search-cancel:hover {
    transform: translateY(-1px);
}

.books-search-close {
    background: rgba(8, 16, 34, 0.72);
}

@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%);
    }

    .modal-content::before {
        content: '';
        position: absolute;
        inset: 0;
        pointer-events: none;
        border-radius: inherit;
        background: linear-gradient(155deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.04) 34%, rgba(255, 255, 255, 0.02) 70%);
        mix-blend-mode: screen;
    }
}

@keyframes zoomIn {
    from {
        transform: scale(0.7);
        opacity: 0;
    }
    to {
        transform: scale(1);
        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;
    }
}

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

@keyframes starDrift {
    from {
        background-position: 0 0, 0 0, 0 0, 0 0, 0 0, 0 0;
    }
    to {
        background-position: 180px 90px, -140px 100px, 100px -120px, -90px -80px, 120px -60px, -110px 70px;
    }
}

@keyframes shootingStar {
    0% {
        opacity: 0;
        transform: rotate(-24deg) translate3d(0, 0, 0) scaleX(0.35);
    }
    78% {
        opacity: 0;
        transform: rotate(-24deg) translate3d(0, 0, 0) scaleX(0.35);
    }
    80% {
        opacity: 0.95;
        transform: rotate(-24deg) translate3d(-8px, 6px, 0) scaleX(1);
    }
    84% {
        opacity: 0.9;
        transform: rotate(-24deg) translate3d(-300px, 190px, 0) scaleX(1);
    }
    88% {
        opacity: 0;
        transform: rotate(-24deg) translate3d(-520px, 330px, 0) scaleX(0.75);
    }
    100% {
        opacity: 0;
        transform: rotate(-24deg) translate3d(-520px, 330px, 0) scaleX(0.75);
    }
}

/* Modo rendimiento para móvil / dispositivos modestos */
@media (max-width: 900px), (prefers-reduced-motion: reduce) {
    html::before,
    html::after,
    body::before,
    body::after {
        content: none !important;
        animation: none !important;
        filter: none !important;
    }

    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,
    .book-info,
    .modal-content,
    .book-search-btn,
    .book-scroll-top-btn,
    .header {
        box-shadow: 0 2px 8px rgba(2, 8, 18, 0.24) !important;
    }
}
