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

html {
    -webkit-text-size-adjust: 100%;
}

:root {
    --font: "Bigelow Rules", cursive;
}

body {
    margin: 0;
    background: #ffffff;
    color: #000000;
}

/* Full width with 16 px side gaps; the parents and the hero keep their own max-widths. */
main {
    padding: clamp(1.5rem, 4vw, 4rem) 16px;
    display: flex;
    flex-direction: column;
    gap: clamp(2rem, 5vw, 4.5rem);
}

/* Sections */

.parents,
.gallery {
    --gap: clamp(2rem, 4vw, 4rem);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--gap);
    align-items: start;
}

/* Side margins of the gallery as wide as the gaps between the frames (main already has 16 px). */
@media (min-width: 701px) {
    .gallery {
        padding-inline: calc(var(--gap) - 16px);
    }
}

.parents {
    /* Two square frames of up to 540 px each – slightly smaller than the 620 px hero. */
    max-width: 1144px;
    width: 100%;
    margin: 0 auto;
}

.hero {
    width: 100%;
    max-width: 620px;
    margin: 0 auto;
}

/* Portrait frames are tall – keep them from towering over landscape neighbours. */
.gallery .item--portrait .frame {
    width: 72%;
    margin: 0 auto;
}

/* Three gallery columns from 1400 px, two in between, one below 900 px. The parents go under each other on phones. */
@media (min-width: 1400px) {
    .gallery {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 899px) {
    .gallery {
        grid-template-columns: minmax(0, 1fr);
    }

    /* At most as wide as the main photo, so a single column doesn't blow the frames up. */
    .gallery .item {
        width: 100%;
        max-width: 620px;
        justify-self: center;
    }

    .gallery .item--portrait .frame {
        width: 100%;
    }
}

@media (max-width: 700px) {
    .parents {
        grid-template-columns: minmax(0, 1fr);
    }

    .parents .item {
        width: 88%;
        margin: 0 auto;
    }
}

/* Framed item */

.frame-link {
    display: block;
}

.item {
    margin: 0;
}

.frame {
    position: relative;
    width: 100%;
}

.frame__window {
    position: absolute;
    left: var(--win-left);
    top: var(--win-top);
    width: var(--win-width);
    height: var(--win-height);
    overflow: hidden;
    background: #e9e4dc;
}

.frame__window img,
.frame__window video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.frame__border,
.frame__border img {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

figcaption {
    margin-top: 0.6rem;
    font-family: var(--font);
    font-size: clamp(2.2rem, 1.6rem + 1.6vw, 3rem);
    line-height: 1.2;
    text-align: center;
    color: #000000;
    overflow-wrap: anywhere;
}

/* Puppy age and homecoming countdown under the hero */

.puppy-line {
    margin: 0.4rem 0 0;
    font-family: var(--font);
    font-size: clamp(2.2rem, 1.6rem + 1.7vw, 3.1rem);
    line-height: 1.2;
    text-align: center;
}

.day-note {
    margin: 0;
    font-family: var(--font);
    font-size: clamp(2.2rem, 1.6rem + 1.7vw, 3.1rem);
    line-height: 1.2;
    text-align: center;
    overflow-wrap: anywhere;
}

figcaption + .puppy-line {
    margin-top: 3.5rem;
}

.gallery__empty {
    grid-column: 1 / -1;
    margin: 0;
    font-family: var(--font);
    font-size: clamp(1.9rem, 1.4rem + 1.4vw, 2.6rem);
    text-align: center;
}

/* Paw following the mouse */

.paw {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 2147483647;
    width: 25px;
    height: auto;
    pointer-events: none;
    opacity: 0;
    will-change: transform;
}

.paw--visible {
    opacity: 1;
}

/* Year filter: small parchment button showing the active filter, and the parchment dialog */

.years-button {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 100;
    display: grid;
    place-items: center;
    --menu-width: 130px;
    width: var(--menu-width);
    height: calc(var(--menu-width) * 219 / 320);
    /* Centre the label on the paper (slightly left of and below the image centre), not on the whole image. */
    padding: calc(var(--menu-width) * 0.07) calc(var(--menu-width) * 0.05) 0 0;
    border: 0;
    background: url("/images/parchment-menu.webp") center / contain no-repeat;
    color: #000000;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    filter: drop-shadow(0 3px 5px rgb(0 0 0 / 0.25));
}

/* A book in the top left corner (a link to a document), a little larger than the menu and further from the edges. */
.book-link {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 100;
    --menu-width: 130px;
    height: calc(var(--menu-width) * 219 / 320 * 1.25);
    -webkit-tap-highlight-color: transparent;
    filter: drop-shadow(0 3px 5px rgb(0 0 0 / 0.25));
}

.book-link img {
    display: block;
    width: auto;
    height: 100%;
}

/* One hover effect for every clickable picture: the menu, the book, the Easter egg, the Christmas tree, the presents
   and the April Fools' main photo.
   Hover only on devices that really hover, so a tap on a phone doesn't leave the picture enlarged. */
.years-button,
.book-link,
.easter-egg,
.christmas-tree,
.presents,
.frame-link {
    transition: transform 0.15s ease;
}

@media (hover: hover) {
    .years-button:hover,
    .book-link:hover,
    .easter-egg:hover,
    .christmas-tree:hover,
    .presents:hover,
    .frame-link:hover {
        transform: scale(1.05);
    }
}

.years-button:focus-visible,
.book-link:focus-visible,
.easter-egg:focus-visible,
.christmas-tree:focus-visible,
.presents:focus-visible,
.frame-link:focus-visible {
    transform: scale(1.05);
}

.years-button__label {
    font-family: var(--font);
    font-size: 2.1rem;
    line-height: 1;
    white-space: nowrap;
}

.years {
    /* Explicit height: Safari ignores aspect-ratio on a modal dialog (it is stretched by inset: 0). */
    --years-width: min(90vw, 480px, 62vh);
    width: var(--years-width);
    height: calc(var(--years-width) * 1.5);
    max-width: none;
    max-height: none;
    padding: 0;
    border: 0;
    background: url("/images/parchment.webp") center / contain no-repeat;
    color: #000000;
    outline: none;
}

.years::backdrop {
    background: rgb(255 255 255 / 0.8);
}

.years__list {
    position: absolute;
    inset: 20% 14%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.2rem;
    overflow-y: auto;
}

/* Many years: „Zobrazit vše“ on top, the years in two columns below it. */
.years__list--columns {
    display: grid;
    grid-template-columns: repeat(2, auto);
    align-content: center;
    justify-content: center;
    column-gap: 1.5rem;
    row-gap: 0;
}

.years__list--columns button {
    padding-block: 0;
}

.years__list--columns button:first-child {
    grid-column: 1 / -1;
}

.years__list button {
    padding: 0.1rem 0.6rem;
    border: 0;
    background: none;
    color: inherit;
    font-family: var(--font);
    font-size: clamp(1.9rem, 1.4rem + 1.4vw, 2.6rem);
    line-height: 1.2;
    cursor: pointer;
}

/* The active choice gets a little heart on its left, placed outside the text so the list doesn't shift. */
.years__list button.is-active {
    position: relative;
}

.years__list button.is-active::before {
    content: "";
    position: absolute;
    top: 50%;
    right: calc(100% - 0.4rem);
    width: 0.7em;
    aspect-ratio: 1;
    translate: 0 -50%;
    background: url("/images/heart.webp") center / contain no-repeat;
}

.years__list button:focus-visible {
    outline: 1px dashed currentColor;
}

/* Where the parents come close to the screen edge, start the page below the parchment and the book so they don't cover them. */
@media (max-width: 1480px) {
    main {
        padding-top: 140px;
    }
}

@media (max-width: 700px) {
    .years-button,
    .book-link {
        --menu-width: 112px;
    }

    .years-button__label {
        font-size: 1.8rem;
    }

    main {
        padding-top: 124px;
    }
}

/* Seasons (App\Season): repeating background tiles shown at half their pixel size, so they stay sharp on retina. */

.season-valentine {
    background: #ffffff url("/images/seasonal/background-valentine.webp") 0 0 / 627px repeat;
}

.season-spring {
    background: #ffffff url("/images/seasonal/background-spring.webp") 0 0 / 627px repeat;
}

.season-easter {
    background: #ffffff url("/images/seasonal/background-easter-2.webp") 0 0 / 768px repeat;
}

.season-halloween {
    background: #ffffff url("/images/seasonal/background-halloween.webp") 0 0 / 768px repeat;
}

.season-christmas {
    background: #ffffff url("/images/seasonal/background-christmas.webp") 0 0 / 768px repeat;
}

.season-birthday {
    background: #ffffff url("/images/seasonal/background-birthday.webp") 0 0 / 768px repeat;
}

/* Texts get a white backing so they stay readable over the busy seasonal backgrounds. */
.season figcaption,
.season .puppy-line,
.season .day-note,
.season .gallery__empty:not([hidden]) {
    width: fit-content;
    max-width: 100%;
    margin-inline: auto;
    padding: 0.05em 0.6em;
    border-radius: 0.5em;
    background: #ffffff;
    box-shadow: 0 0 0.6em 0.4em #ffffff;
}

.season-valentine .caption--season {
    color: #e0457b;
    font-size: clamp(2.8rem, 2rem + 2.4vw, 4rem);
}

/* Halloween: a pumpkin lantern standing on each side of the main photo, the middle layer flickering like a flame. */

.lantern {
    display: none;
}

@media (min-width: 1400px) {
    .lantern {
        display: block;
        position: absolute;
        bottom: 0;
        width: clamp(140px, 14vw, 200px);
        aspect-ratio: 1337 / 1177;
        pointer-events: none;
    }

    .lantern--left {
        right: calc(100% + 1.5rem);
    }

    .lantern--right {
        left: calc(100% + 1.5rem);
    }

    .lantern img {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
    }

    .lantern__flame {
        animation: lantern-flame 2.5s ease-in-out infinite alternate;
    }
}

@keyframes lantern-flame {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Easter: an egg that swaps between its two pictures on click – right of the main photo on wide screens, under it otherwise. */

.easter-egg {
    position: relative;
    display: block;
    width: min(50%, 220px);
    aspect-ratio: 400 / 593;
    margin: 2rem auto 0;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.easter-egg__img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.easter-egg[aria-pressed="false"] .easter-egg__img:last-child,
.easter-egg[aria-pressed="true"] .easter-egg__img:first-child {
    visibility: hidden;
}

@media (min-width: 1400px) {
    /* The egg shares the main photo's grid cell and is pushed out beside it, so the hero itself doesn't move. */
    .season-easter .hero {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
    }

    .season-easter .hero > .item,
    .easter-egg {
        grid-row: 1;
        grid-column: 1;
    }

    .easter-egg {
        align-self: center;
        justify-self: end;
        width: clamp(140px, 14vw, 200px);
        margin: 0;
        translate: calc(100% + 1.5rem);
    }
}

/* Birthday: presents on both sides of the main photo (links to a shop), only the left one under it below 1400 px. */

.presents {
    display: block;
    width: min(75%, 320px);
    margin: 2rem auto 0;
    -webkit-tap-highlight-color: transparent;
}

.presents img {
    display: block;
    width: 100%;
    height: auto;
}

.presents--right {
    display: none;
}

@media (min-width: 1400px) {
    /* Same trick as the Easter egg: the presents share the main photo's grid cell and are pushed out beside it. */
    .season-birthday .hero {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
    }

    .season-birthday .hero > .item,
    .presents {
        grid-row: 1;
        grid-column: 1;
    }

    .presents {
        display: block;
        align-self: center;
        /* As wide as the space beside the 620 px hero allows, up to 320 px. */
        width: min(320px, (100vw - 620px) / 2 - 2.5rem);
        margin: 0;
    }

    .presents--left {
        justify-self: start;
        translate: calc(-100% - 1.5rem);
    }

    .presents--right {
        justify-self: end;
        translate: calc(100% + 1.5rem);
    }
}

/* Christmas: a tree right of the main photo (a link to a Christmas song), under it below 1400 px. */

.christmas-tree {
    display: block;
    width: min(85%, 400px);
    margin: 2rem auto 0;
    -webkit-tap-highlight-color: transparent;
}

.christmas-tree img {
    display: block;
    width: 100%;
    height: auto;
}

@media (min-width: 1400px) {
    /* Same trick as the presents: the tree shares the main photo's grid cell and is pushed out beside it. */
    .season-christmas .hero {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
    }

    .season-christmas .hero > .item,
    .christmas-tree {
        grid-row: 1;
        grid-column: 1;
    }

    .christmas-tree {
        align-self: center;
        justify-self: end;
        width: min(420px, (100vw - 620px) / 2 - 3rem);
        margin: 0;
        translate: calc(100% + 2.5rem);
    }
}

/* Birthday card popup, opened on page load; a click anywhere closes it. */

.birthday-card {
    /* Explicit height: Safari ignores aspect-ratio on a modal dialog. */
    --card-size: min(90vw, 85vh, 600px);
    width: var(--card-size);
    height: var(--card-size);
    max-width: none;
    max-height: none;
    padding: 0;
    border: 0;
    background: none;
    outline: none;
    cursor: pointer;
}

.birthday-card::backdrop {
    background: rgb(255 255 255 / 0.8);
}

/* The shadow sits on the image: a filter on the dialog would make it the containing block of the fixed paw. */
.birthday-card__img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 6px 18px rgb(0 0 0 / 0.3));
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
