/* Home (home.hbs). Loaded after built/screen.css and book.css; no rebuild needed.
   The page shown on the home is a list of blocks separated by dividers, in two columns:
   - a block that starts with an image: the image on the left, no taller than the block, the rest on the right;
   - a block that starts with its heading: the heading on the left, the rest on the right;
   - if the page has a feature image, it sits on the left of everything above the first divider. */

.gh-home-page {
    padding-top: 40px;
    padding-bottom: 96px;
}

/* Two columns: images on the left, text on the right */
#main-content .gh-home-page .gh-book .gh-book-content {
    display: grid;
    grid-template-columns: var(--book-cover-width) minmax(0, 1fr);
    column-gap: var(--book-gap);
}

#main-content .gh-home-page .gh-book .gh-book-content::after {
    display: none;
}

#main-content .gh-home-page .gh-book .gh-book-content > * {
    grid-column: 2;
    max-width: 720px;
    margin-right: 0;
    margin-left: 0;
}

/* The cover, beside everything above the divider. No title above the content here,
   so the first heading starts level with the top of the cover. */
#main-content .gh-home-page .gh-book .gh-book-content > .gh-book-cover {
    grid-row: span 100;
    grid-column: 1;
    float: none;
    align-self: start;
    width: 100%;
    max-width: none;
    margin: 0;
}

#main-content .gh-home-page .gh-book .gh-book-content > .gh-book-cover + *,
#main-content .gh-home-page .gh-book .gh-book-content > :first-child:not(.gh-book-cover) {
    margin-top: 0;
}

#main-content .gh-home-page .gh-book .gh-book-content > hr {
    grid-column: 1 / -1;
    max-width: none;
    margin: 72px 0;
}

/* A block that starts with its heading: the heading on the left, level with the first line of text */
#main-content .gh-home-page .gh-book .gh-book-content > :is(h2, h3):first-child,
#main-content .gh-home-page .gh-book .gh-book-content > hr + :is(h2, h3) {
    grid-row: span 100;
    grid-column: 1;
    align-self: start;
    margin-top: 0;
}

#main-content .gh-home-page .gh-book .gh-book-content > :is(h2, h3):first-child + *,
#main-content .gh-home-page .gh-book .gh-book-content > hr + :is(h2, h3) + * {
    margin-top: 0.35em;
}

/* A block that starts with an image: the image beside the block, as tall as the block,
   its right edge against the gap between the two columns */
#main-content .gh-home-page .gh-book .gh-book-content > hr + .kg-image-card {
    position: relative;
    grid-row: span 100;
    grid-column: 1;
    max-width: none;
    margin: 0;
}

/* Never cropped: the image is as tall as the block when the column is wide enough,
   and as wide as the column otherwise */
#main-content .gh-home-page .gh-book .gh-book-content > hr + .kg-image-card img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: right top;
}

/* !important: Solo forces a top margin on a heading that follows a card */
#main-content .gh-home-page .gh-book .gh-book-content > hr + .kg-image-card + * {
    margin-top: 0 !important;
}

/* The three latest posts */
.gh-home-latest {
    padding-bottom: 96px;
}

.gh-home-latest-title {
    margin-bottom: 40px;
    font-size: calc(clamp(2.8rem, 1.36vw + 2.25rem, 4rem));
    font-weight: 800;
    line-height: 1.2;
}

.gh-home-latest-more {
    display: inline-flex;
    margin-top: 48px;
}

@media (max-width: 767px) {
    .gh-home-page {
        padding-top: 16px;
        padding-bottom: 64px;
    }

    /* One column: each image above its block */
    #main-content .gh-home-page .gh-book .gh-book-content {
        display: block;
    }

    #main-content .gh-home-page .gh-book .gh-book-content > .gh-book-cover {
        width: 240px;
        max-width: 70%;
        margin: 0 auto 40px;
    }

    #main-content .gh-home-page .gh-book .gh-book-content > hr {
        margin: 48px 0;
    }

    #main-content .gh-home-page .gh-book .gh-book-content > :is(h2, h3):first-child + *,
    #main-content .gh-home-page .gh-book .gh-book-content > hr + :is(h2, h3) + * {
        margin-top: 0.8em;
    }

    #main-content .gh-home-page .gh-book .gh-book-content > hr + .kg-image-card {
        width: 160px;
        margin: 0 auto 32px;
    }

    #main-content .gh-home-page .gh-book .gh-book-content > hr + .kg-image-card img {
        position: static;
        width: 100%;
        height: auto;
    }
}

/* ---------- Blocks: fade and slide up ----------
   The same effect as on mbaderot.erwanripoll.com. Below the intro, each block of the home page
   (a heading, a paragraph, a quote, a button, an image, a divider), each of the latest posts and
   the button under them fades in and slides up as it scrolls into the window: text from 100 px
   to 200 px above the bottom edge, the taller blocks (images and posts) from 160 px to 320 px.
   The fade follows the scroll. When the scrolling stops, assets/js/home.js finishes the fade of
   every block that is on screen (class `is-shown`), so no text is left half transparent, below
   the contrast minimum, while someone reads.
   Without scripts, in a browser without `animation-timeline`, for a visitor who asked for less
   motion, and in print, every block shows as it is. A block that holds the keyboard focus is
   never faded. */

@keyframes fade-slide-up {
    from {
        opacity: 0;
        transform: translateY(24px);
    }
}

@media screen and (scripting: enabled) and (prefers-reduced-motion: no-preference) {
    @supports (animation-timeline: view()) {
        :where(
            .gh-home-page .gh-book-content > *,
            .gh-home-latest-title,
            .gh-home-latest .gh-card,
            .gh-home-latest-more
        ):not(:focus-within):not(.is-shown) {
            animation: fade-slide-up linear both;
            animation-timeline: view();
            animation-range: entry 100px entry 200px;
        }

        :where(
            .gh-home-page .gh-book-content > .kg-image-card,
            .gh-home-page .gh-book-content > .gh-book-cover,
            .gh-home-latest .gh-card
        ):not(:focus-within):not(.is-shown) {
            animation-range: entry 160px entry 320px;
        }
    }
}
