/* Shared responsive layout for every page */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    overflow-x: hidden;
}

img,
iframe {
    max-width: 100%;
}

/* Cloud transition between pages */
.cloud-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.cloud-part {
    position: absolute;
    background: #fff;
    border-radius: 50%;
    transform: scale(0);
    transition: transform 0.8s cubic-bezier(0.65, 0, 0.35, 1);
}

.cloud-overlay.active .cloud-part {
    transform: scale(1);
}

.cloud-part.c1 {
    width: 150vmax;
    height: 150vmax;
}

.cloud-part.c2 {
    width: 100vmax;
    height: 100vmax;
    top: -30vh;
    left: -20vw;
    transition-delay: 0.1s;
}

.cloud-part.c3 {
    width: 120vmax;
    height: 120vmax;
    right: -20vw;
    bottom: -20vh;
    transition-delay: 0.2s;
}

/* Main library */
.library-container {
    width: min(100%, 1340px);
    padding-inline: clamp(10px, 3vw, 40px);
}

.title-wrapper {
    max-width: 100%;
}

.main-title {
    font-size: clamp(1.45rem, 4vw, 3rem);
}

.bookcase {
    width: 100%;
    padding-inline: clamp(10px, 3vw, 40px);
}

.shelf {
    min-height: 240px;
    height: auto;
    gap: clamp(12px, 2vw, 30px);
    flex-wrap: wrap;
    padding: 20px 10px 15px;
}

/* Photo, event and gallery pages */
body {
    max-width: 100%;
    overflow-x: hidden;
}

.photos-wrapper {
    max-width: calc(100% - 24px);
}

.photos-section {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(16px, 3vw, 40px);
}

.photo-container img {
    max-width: 100%;
}

/* Top-book pages */
.books-section {
    width: min(94vw, 1400px);
    flex-wrap: wrap;
    gap: clamp(18px, 4vw, 50px);
    margin-bottom: clamp(40px, 12vh, 120px);
}

.book-item {
    width: clamp(130px, 28vh, 300px);
    height: clamp(195px, 42vh, 450px);
}

.videos-section {
    width: min(94vw, 1400px);
    flex-wrap: wrap;
    gap: clamp(18px, 4vw, 50px);
}

.video-container iframe {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
}

/* Book detail pages */
body:has(> .container) {
    width: auto;
    min-height: 100vh;
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
}

.container {
    width: 100%;
    min-height: calc(100vh - 4vh);
    height: auto;
}

.main-content {
    flex-wrap: wrap;
    align-items: stretch;
}

.book-cover {
    width: min(25%, 260px);
    min-width: 140px;
    height: auto;
    max-height: 435px;
}

body:has(> .container) .video-container {
    flex: 1 1 480px;
    width: auto;
    max-width: 100%;
    height: auto;
    min-height: 0;
    aspect-ratio: 16 / 10;
}

body:has(> .container) .video-container iframe {
    height: auto;
    aspect-ratio: 16 / 9;
}

.bottom-bar {
    flex-wrap: wrap;
    height: auto;
    min-height: 0;
}

.book-info,
.quote-box {
    min-width: 0;
    height: auto;
    min-height: 120px;
}

@media (max-width: 1100px) {
    .planet-icon {
        width: clamp(150px, 25vw, 250px);
    }

    .shelf {
        justify-content: center;
    }

    .book-img {
        width: clamp(92px, 14vw, 140px);
        height: clamp(132px, 20vw, 200px);
    }

    .icon-img {
        width: clamp(90px, 14vw, 120px);
        height: clamp(90px, 14vw, 120px);
    }

    .top-book-img {
        width: clamp(150px, 20vw, 220px);
        height: auto;
    }
}

@media (max-width: 768px) {
    .title-wrapper {
        display: block;
        padding: 18px 42px 18px 18px;
        margin-bottom: 28px;
        border-radius: 32px;
    }

    .age-mark {
        right: 8px;
        width: 29px;
        height: 29px;
        font-size: 13px;
    }

    .bookcase {
        border-width: 12px;
        border-radius: 28px 28px 14px 14px;
    }

    .shelf {
        min-height: 0;
        border-bottom-width: 26px;
        margin-bottom: 22px;
        padding-bottom: 12px;
    }

    .shelf::after {
        bottom: -26px;
    }

    .item:hover {
        transform: translateY(-8px) scale(1.03);
    }

    .photos-wrapper {
        width: calc(100% - 20px);
        max-width: none;
        padding: 14px;
        border-radius: 16px;
    }

    .photos-section {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .gallery-title {
        width: 100%;
        padding-inline: 10px;
        font-size: clamp(18px, 5vw, 26px);
    }

    .back-btn {
        left: 12px;
        top: 12px;
        padding: 8px 12px;
        letter-spacing: 0;
    }

    .page-title {
        max-width: calc(100% - 20px);
        margin-top: 72px;
        font-size: clamp(24px, 7vw, 38px);
    }

    .books-section {
        margin-top: 74px;
        margin-bottom: 50px;
    }

    .book-item {
        width: clamp(105px, 31vw, 180px);
        height: clamp(158px, 47vw, 270px);
        border-width: 5px;
    }

    .videos-section {
        width: calc(100% - 24px);
        flex-direction: column;
    }

    .videos-section .video-container {
        width: 100%;
        max-width: 600px;
        flex-basis: auto;
    }

    body:has(> .container) {
        padding: 10px;
    }

    body:has(> .container) .container {
        min-height: 0;
        padding: 12px;
        border-radius: 14px;
    }

    body:has(> .container) header {
        height: auto;
        min-height: 70px;
        flex-wrap: wrap;
        gap: 12px;
    }

    body:has(> .container) .dynamic-title {
        order: 3;
        flex-basis: 100%;
        margin: 0;
    }

    body:has(> .container) .emblem {
        height: 55px;
        max-width: 90px;
    }

    body:has(> .container) .main-content {
        display: grid;
        grid-template-columns: minmax(90px, 30%) 1fr;
        gap: 12px;
    }

    body:has(> .container) .book-cover {
        width: 100%;
        min-width: 0;
        max-height: 260px;
        grid-row: span 2;
    }

    body:has(> .container) .book-info {
        min-height: 130px;
        font-size: clamp(14px, 3.5vw, 20px);
    }

    body:has(> .container) .video-container {
        grid-column: 1 / -1;
        width: 100%;
        aspect-ratio: auto;
    }

    body:has(> .container) .video-container iframe {
        width: 100%;
        aspect-ratio: 16 / 9;
    }

    body:has(> .container) .bottom-bar,
    body:has(> .container) .quote-box {
        width: 100%;
    }

    body:has(> .container) .quote-box {
        flex-wrap: wrap;
        justify-content: center;
        text-align: center;
    }

    body:has(> .container) .quote {
        flex-basis: 100%;
        font-size: clamp(14px, 3.5vw, 18px);
    }

    body:has(> .container) .qr-code {
        height: 100px;
    }
}

@media (max-width: 420px) {
    .library-container {
        padding-inline: 6px;
    }

    .main-title {
        -webkit-text-stroke-width: 0.8px;
    }

    .icon-text,
    .top-book-caption {
        max-width: 140px;
        white-space: normal;
        font-size: 0.8em;
        padding: 6px 8px;
    }

    body:has(> .container) .main-content {
        grid-template-columns: 1fr;
    }

    body:has(> .container) .book-cover {
        grid-row: auto;
        width: min(65%, 180px);
        justify-self: center;
    }
}

/* Book 4 page layout */
.book4-page .feature-layout {
    align-items: stretch;
}

.book4-page .feature-layout > .book-info,
.book4-page .feature-layout > .bottom-bar {
    height: 100%;
    min-height: 320px;
}

.book4-page .video-container {
    height: auto;
}

.book4-page .video-container iframe {
    height: auto;
    aspect-ratio: 16 / 9;
}

@media (max-width: 900px) {
    .book4-page .videos-section {
        grid-template-columns: repeat(2, minmax(0, 420px));
        width: min(94vw, 900px);
        gap: 30px;
    }
}

@media (max-width: 760px) {
    .book4-page main {
        padding-top: 90px;
    }

    .book4-page .feature-layout {
        grid-template-columns: 1fr;
    }

    .book4-page .book-cover {
        width: min(65vw, 280px);
        height: auto;
    }

    .book4-page .feature-layout > .book-info,
    .book4-page .feature-layout > .bottom-bar {
        height: auto;
        min-height: 150px;
    }

    .book4-page .videos-section {
        grid-template-columns: 1fr;
        width: 100%;
        gap: 24px;
    }
}
