:root {
    --home-nav-width: 100px;
}

@font-face {
    font-family: 'HanYiBaoSongJian';
    src: url('../resources/font/HanYiBaoSongJian/HanYiBaoSongJian-1.ttf') format('truetype');
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

:root {
    --page-top: var(--home-space-top);
    --page-right: var(--home-space-left);
    --catalog-left: 216px;
    --catalog-width: 144px;
    --gallery-left: 400px;
}

.home-container {
    padding: var(--page-top) var(--page-right) var(--home-space-bottom) var(--gallery-left);
}

.album-catalog {
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: fixed;
    top: var(--page-top);
    left: var(--catalog-left);
    width: var(--catalog-width);
}

.album-catalog a {
    color: #777;
    font-size: 12px;
    font-weight: 300;
    line-height: 1.2;
    text-decoration: none;
    overflow-wrap: anywhere;
    transition: color 0.2s ease;
}

.album-catalog a:hover,
.album-catalog a.is-active {
    color: var(--text);
}

.album-catalog a.is-japanese,
.album-title.is-japanese {
    font-family: 'HanYiBaoSongJian', sans-serif;
}

.album-catalog a:focus-visible {
    outline: 1px solid #777 !important;
    outline-offset: 5px;
}

.home-main {
    width: min(100%, 70vw);
    margin-left: auto;
    container-type: inline-size;
}

/*
 * Albums sit on equal columns. Each photo keeps its full ratio with its
 * long edge equal to the column width, centred in its column; each row is
 * only as tall as its tallest photo.
 */
.album {
    --cols: var(--album-cols, 2);
    --gutter: calc(100cqw / (8 * var(--cols)));
    --cell: calc((100cqw - (var(--cols) - 1) * var(--gutter)) / var(--cols));
    scroll-margin-top: var(--page-top);
}

.album + .album {
    margin-top: max(96px, calc(var(--gutter) * 3));
}

.album-title {
    display: none;
}

.album-grid {
    display: grid;
    grid-template-columns: repeat(var(--cols), var(--cell));
    align-items: center;
    gap: var(--gutter);
}

.album-photo {
    position: relative;
    display: block;
    place-self: center;
    width: calc(var(--cell) * min(1, var(--ratio, 1.5)));
    aspect-ratio: var(--ratio, 1.5);
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    color: inherit;
    font: inherit;
    appearance: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.album-photo:focus-visible {
    outline: 1px solid #777 !important;
    outline-offset: 5px;
}

.album-photo img {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0.6s ease;
}

.album-photo img.is-loaded {
    opacity: 1;
}

html.has-photo-zoom {
    overflow: hidden;
    scrollbar-gutter: stable;
}

/* Shows one photo in place of the grid; the nav and album list stay in view. */
.photo-zoom {
    --zoom-head: 40px;
    --zoom-bottom: 56px;
    --zoom-fade: 0.22s;
    --zoom-swap: 0.45s;
    position: fixed;
    inset: 0 0 0 var(--gallery-left);
    z-index: 70;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    overflow: hidden;
    background: var(--bg);
    color: #777;
    opacity: 0;
    transition: opacity var(--zoom-fade) ease;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.photo-zoom.is-open {
    opacity: 1;
}

.photo-zoom-bar {
    position: absolute;
    top: var(--page-top);
    left: 0;
    right: var(--page-right);
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 12px;
    font-weight: 300;
    line-height: 1.2;
    white-space: nowrap;
}

/* The album list already marks the album on wide screens. */
.photo-zoom-album {
    display: none;
    margin-right: 10px;
    color: var(--text);
}

.photo-zoom-count {
    font-variant-numeric: tabular-nums;
    text-align: center;
}

.photo-zoom-bar button {
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    appearance: none;
    cursor: pointer;
    transition: color 0.2s ease;
}

.photo-zoom-bar button:hover,
.photo-zoom-bar button:focus-visible {
    color: var(--text);
}

.photo-zoom-close {
    margin-left: auto;
}

.photo-zoom-frame {
    position: absolute;
    top: calc(var(--page-top) + var(--zoom-head));
    left: 0;
    right: var(--page-right);
    bottom: var(--zoom-bottom);
    isolation: isolate;
}

/* Two stacked layers so one photo can fade into the next. The shown photo sits on top and the
   other layer is hidden once it has faded out, so right-click / long-press always gets the photo
   on screen (Chrome looks through the transparent step buttons for the topmost image). */
.photo-zoom-image {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: left top;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--zoom-swap) ease, visibility var(--zoom-swap) linear;
}

.photo-zoom-image.is-front {
    z-index: 1;
    opacity: 1;
    visibility: visible;
}

/* Covers just the visible photo; set from script. Clicks elsewhere close the viewer. */
.photo-zoom-hit {
    position: absolute;
    z-index: 2;
    left: 0;
    top: 0;
    width: 0;
    height: 0;
}

/* Each half of the photo steps back or forward. */
.photo-zoom-step {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 50%;
    padding: 0;
    border: 0;
    background: none;
    appearance: none;
}

.photo-zoom-step.is-prev {
    left: 0;
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='-181.8 -811.8 963.7 963.7'%3E%3Cpath transform='scale(1 -1)' fill='%23fff' d='M510 80 90 307V353L510 580V527L219 373Q198 362 174.5 350.0Q151 338 137 331Q151 324 174.5 312.0Q198 300 219 289L510 133Z'/%3E%3C/svg%3E") 12 12, w-resize;
}

.photo-zoom-step.is-next {
    right: 0;
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='-181.8 -811.8 963.7 963.7'%3E%3Cpath transform='scale(1 -1)' fill='%23fff' d='M90 80V133L381 287Q402 298 425.5 310.0Q449 322 463 329Q449 336 425.5 348.0Q402 360 381 371L90 527V580L510 353V307Z'/%3E%3C/svg%3E") 12 12, e-resize;
}

.photo-zoom.is-single .photo-zoom-step,
.photo-zoom.is-single .photo-zoom-nav,
.photo-zoom.is-single .photo-zoom-count {
    display: none;
}

/* A single column keeps each cell within the screen height. */
@container (max-width: 599.98px) {
    .album {
        --cols: 1;
        --gutter: calc(100cqw / 16);
        --cell: min(100cqw, 100svh - 2 * var(--page-top));
    }
}

@media (max-width: 980px) {
    :root {
        --page-top: 56px;
        --page-right: 36px;
        --catalog-left: 162px;
        --catalog-width: 150px;
        --gallery-left: 342px;
    }
}

@media (max-width: 720px) {
    html,
    body {
        overscroll-behavior-y: none;
    }

    :root {
        --page-top: calc(env(safe-area-inset-top) + 32px);
        --page-right: 14px;
        --gallery-left: 14px;
    }

    .album-catalog {
        position: static;
        margin: 28px 0 40px;
        width: auto;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px 24px;
    }

    .home-container {
        padding-bottom: 54px;
    }

    .home-main {
        width: 100%;
    }

    .album {
        scroll-margin-top: calc(var(--page-top) + 16px);
    }

    .album + .album {
        margin-top: 72px;
    }

    .album-title {
        display: block;
        margin-bottom: 14px;
        color: #777;
        font-size: 12px;
        font-weight: 300;
        line-height: 1.2;
    }

    /* Full width under the fixed top nav. */
    .photo-zoom {
        --zoom-head: 36px;
        --zoom-bottom: calc(env(safe-area-inset-bottom) + 24px);
        left: 0;
    }

    .photo-zoom-bar {
        top: calc(var(--page-top) + 16px);
        left: var(--gallery-left);
    }

    .photo-zoom-frame {
        top: calc(var(--page-top) + 16px + var(--zoom-head));
        left: var(--gallery-left);
    }

    .photo-zoom-album {
        display: inline;
    }
}

@media (max-width: 420px) {
    :root {
        --page-top: calc(env(safe-area-inset-top) + 31px);
        --page-right: 10px;
        --gallery-left: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .album-catalog a,
    .album-photo img,
    .photo-zoom,
    .photo-zoom-image {
        transition: none;
    }
}
