/*
 * The souvenir library and its flipbook reader.
 *
 * The reader is dark and fills the window on purpose. A souvenir page is
 * portrait and full of small print, so the height of the window is what
 * decides whether it can be read at all - every heading stacked above the book
 * costs the reader real size. The first build sat the book inside the ordinary
 * page container and gave each page 395px of a 1707px screen, which is no use
 * to anybody.
 */

/* ------------------------------------------------------------- library -- */

.sv-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 28px;
}

.sv-card {
    display: block;
    background: #fff;
    border: 1px solid #e6eaf0;
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 2px 10px rgba(16, 36, 71, 0.06);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.sv-card:hover,
.sv-card:focus-visible {
    transform: translateY(-4px);
    box-shadow: 0 14px 30px rgba(16, 36, 71, 0.16);
    text-decoration: none;
    color: inherit;
}

.sv-card__media {
    position: relative;
    background: #0b1b36;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 22px 18px 0;
}

.sv-card__media img {
    width: 100%;
    max-width: 190px;
    display: block;
    border-radius: 2px 6px 6px 2px;
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.5), -4px 0 0 rgba(255, 255, 255, 0.28) inset;
}

.sv-card__media--empty {
    min-height: 230px;
    color: #9fb0cc;
    font-size: 42px;
    padding: 18px;
}

.sv-card__year {
    position: absolute;
    top: 12px;
    right: 12px;
    background: #f36f21;
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 0.06em;
    padding: 4px 10px;
    border-radius: 20px;
}

.sv-card__body { padding: 16px 18px 20px; }
.sv-card__title { font-size: 17px; margin: 0 0 6px; color: #10284a; }
.sv-card__meta { font-size: 13px; color: #6b7b94; margin: 0 0 10px; }
.sv-card__desc { font-size: 13.5px; color: #5a6b85; margin: 0 0 12px; line-height: 1.5; }

/* -------------------------------------------------------------- reader -- */

/* Full bleed: the book is the page, not a panel sitting on it. */
.sv-theatre {
    width: 100vw;
    margin-left: calc(50% - 50vw);
    background: #081528;
}

.sv-topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: #061020;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.sv-topbar__back {
    color: #cfdcf2;
    font-size: 13px;
    text-decoration: none;
    white-space: nowrap;
}

.sv-topbar__back:hover { color: #fff; text-decoration: none; }

.sv-topbar__title {
    font-size: 16px;
    color: #fff;
    margin: 0;
    flex: 1 1 auto;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sv-topbar__meta { color: #8fa3c4; font-size: 12.5px; white-space: nowrap; }

.sv-reader {
    --sv-page-w: 420px;
    --sv-page-h: 594px;

    /* Everything the window has, less the site header and this reader's own
       top bar. The book gets the rest. */
    height: calc(100vh - 130px);
    min-height: 520px;
    display: flex;
    flex-direction: column;
    background: radial-gradient(ellipse at 50% 38%, #10243f 0%, #0a1830 45%, #050d1c 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sv-reader.is-ready { opacity: 1; }

.sv-reader:fullscreen { height: 100vh; }

.sv-stage {
    flex: 1 1 auto;
    min-height: 0;             /* let the flex child actually shrink */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px 56px;
    overflow: hidden;
    position: relative;
}

.sv-reader.is-zoomed .sv-stage { cursor: grab; }
.sv-reader.is-zoomed .sv-stage:active { cursor: grabbing; }

.sv-book {
    position: relative;
    display: flex;
    align-items: stretch;
    height: var(--sv-page-h);
    transform-origin: center center;
    perspective: 2600px;
    filter: drop-shadow(0 22px 34px rgba(0, 0, 0, 0.55));
    transition: transform var(--sv-flip, 620ms) cubic-bezier(0.38, 0.03, 0.2, 1);
}

.sv-page {
    width: var(--sv-page-w);
    height: var(--sv-page-h);
    background: #fff;
    position: relative;
    overflow: hidden;
}

.sv-page img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
}

.sv-page--left { border-radius: 3px 0 0 3px; }
.sv-page--right { border-radius: 0 3px 3px 0; }
.sv-page.is-blank { background: transparent; box-shadow: none; }

/*
 * A blank half still holds its place in a two-page book, because the cover and
 * a last odd page are centred by sliding the whole book rather than by
 * resizing it - that is what keeps opening the cover one movement instead of a
 * jump. Showing one page at a time there is no book to balance, so the empty
 * half would just push the page off centre.
 */
.sv-reader:not(.is-double) .sv-page.is-blank { display: none; }

/* The gutter: a printed book is darker where the pages meet the spine. */
.sv-page--left::after,
.sv-page--right::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    pointer-events: none;
}

.sv-page--left::after { right: 0; background: linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.26)); }
.sv-page--right::after { left: 0; background: linear-gradient(to left, rgba(0,0,0,0), rgba(0,0,0,0.26)); }
.sv-page.is-blank::after { display: none; }

/* ------------------------------------------------------------ the turn -- */

.sv-leaf {
    position: absolute;
    top: 0;
    width: var(--sv-page-w);
    height: var(--sv-page-h);
    transform-style: preserve-3d;
    transition: transform var(--sv-flip, 620ms) cubic-bezier(0.38, 0.03, 0.2, 1);
    z-index: 5;
}

.sv-leaf--forward { left: var(--sv-page-w); transform-origin: left center; transform: rotateY(0deg); }
.sv-leaf--forward.is-turning { transform: rotateY(-180deg); }

.sv-leaf--back { left: 0; transform-origin: right center; transform: rotateY(0deg); }
.sv-leaf--back.is-turning { transform: rotateY(180deg); }

.sv-leaf__face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    background: #fff;
    overflow: hidden;
}

.sv-leaf__face img { width: 100%; height: 100%; object-fit: contain; display: block; }
.sv-leaf__face--back { transform: rotateY(180deg); }

/*
 * The curl. Paper does not swap from lit to shaded in one step, so each face
 * carries a gradient that darkens as it turns away from the reader and
 * lightens as it comes round. This is what makes a turn read as paper rather
 * than as a card being flipped.
 */
.sv-leaf__face::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
}

.sv-leaf__face--front::after {
    background: linear-gradient(to left, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0) 55%);
}

.sv-leaf__face--back::after {
    background: linear-gradient(to right, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 60%);
    opacity: 1;
}

.sv-leaf.is-turning .sv-leaf__face--front::after { animation: sv-shade-in var(--sv-flip, 620ms) ease-in forwards; }
.sv-leaf.is-turning .sv-leaf__face--back::after { animation: sv-shade-out var(--sv-flip, 620ms) ease-out forwards; }

@keyframes sv-shade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sv-shade-out { from { opacity: 1; } to { opacity: 0; } }

/* ------------------------------------------------- edges, hint, toolbar -- */

.sv-edge {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 56px;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.28);
    font-size: 26px;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.sv-edge:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.sv-edge--prev { left: 0; }
.sv-edge--next { right: 0; }
.sv-edge.is-off { opacity: 0; pointer-events: none; }
.sv-reader.is-zoomed .sv-edge { display: none; }

.sv-hint {
    position: absolute;
    left: 50%;
    bottom: 10px;
    transform: translateX(-50%);
    margin: 0;
    padding: 5px 14px;
    border-radius: 20px;
    background: rgba(4, 11, 24, 0.78);
    font-size: 12px;
    color: rgba(255, 255, 255, 0.78);
    white-space: nowrap;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.sv-reader.is-touched .sv-hint { opacity: 0; }

.sv-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    flex-wrap: wrap;
    padding: 9px 14px;
    background: #061020;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex: 0 0 auto;
}

.sv-bar__group { display: flex; align-items: center; gap: 6px; }
.sv-bar__group--tools { margin-left: 10px; padding-left: 16px; border-left: 1px solid rgba(255, 255, 255, 0.1); }

.sv-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #e8eefb;
    min-width: 38px;
    height: 36px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 9px;
    transition: background 0.15s ease, opacity 0.15s ease;
}

.sv-btn:hover { background: rgba(255, 255, 255, 0.2); color: #fff; }
.sv-btn.is-off { opacity: 0.3; pointer-events: none; }
.sv-btn.is-on { background: #f36f21; border-color: #f36f21; color: #fff; }
.sv-btn--wide { padding: 0 14px; font-size: 13px; }

.sv-counter { color: #cfdcf2; font-size: 13px; }

.sv-counter__input {
    width: 60px;
    height: 36px;
    text-align: center;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    font-size: 13px;
}

.sv-counter__of { color: #8fa3c4; }
.sv-zoom-level { color: #8fa3c4; font-size: 12px; min-width: 42px; text-align: center; }

/* ------------------------------------------------------------- thumbs -- */

.sv-thumbs {
    max-height: 0;
    overflow: hidden;
    background: #040b18;
    transition: max-height 0.25s ease;
    flex: 0 0 auto;
}

.sv-reader.is-thumbs .sv-thumbs { max-height: 180px; }
.sv-thumbs__strip { display: flex; gap: 10px; padding: 14px; overflow-x: auto; }

.sv-thumb {
    flex: 0 0 auto;
    width: 88px;
    background: none;
    border: 2px solid transparent;
    border-radius: 4px;
    padding: 0;
    cursor: pointer;
    color: #8c9fc0;
    font-size: 11px;
}

.sv-thumb img { width: 100%; display: block; border-radius: 2px; background: #fff; min-height: 56px; }
.sv-thumb.is-current { border-color: #f36f21; color: #fff; }

/* -------------------------------------------------------------- below -- */

.sv-below { padding-top: 34px; }
.sv-below__heading { font-size: 22px; margin-bottom: 14px; }
.sv-below__link { margin: 0 8px 8px 0; }

/* ------------------------------------------------------------- mobile -- */

@media (max-width: 899px) {
    .sv-reader { height: calc(100vh - 128px); min-height: 440px; }
    .sv-stage { padding: 12px 34px; }
    .sv-page--left { display: none; }
    .sv-page--right { border-radius: 3px; }
    .sv-page--right::after { display: none; }
    .sv-edge { width: 34px; font-size: 20px; }
    .sv-topbar__title { font-size: 14px; }
    .sv-topbar__meta, .sv-hint { display: none; }
    .sv-bar { gap: 8px; padding: 8px 6px; }
    .sv-bar__group--tools { margin-left: 0; padding-left: 8px; }
    .sv-btn--wide span { display: none; }
    .sv-btn--wide { padding: 0 9px; }
}

/*
 * Reduced motion shortens the turn rather than removing it.
 *
 * theme.css switches off every transition and animation on the site when the
 * system asks for less motion, with !important on a universal selector. That
 * is right for decoration, and wrong here: turning the page is the thing the
 * reader came to do, and without it this is a slideshow of JPEGs. It took a
 * machine with Windows animations switched off to show it.
 *
 * So the turn is put back, at the shorter duration the script sets in
 * --sv-flip (280ms rather than 620ms), and nothing else is.
 */
@media (prefers-reduced-motion: reduce) {
    .sv-card { transition: none; }

    .sv-reader .sv-leaf,
    .sv-reader .sv-book {
        transition: transform var(--sv-flip, 280ms) cubic-bezier(0.38, 0.03, 0.2, 1) !important;
    }

    .sv-reader .sv-leaf.is-turning .sv-leaf__face--front::after {
        animation: sv-shade-in var(--sv-flip, 280ms) ease-in forwards !important;
    }

    .sv-reader .sv-leaf.is-turning .sv-leaf__face--back::after {
        animation: sv-shade-out var(--sv-flip, 280ms) ease-out forwards !important;
    }
}
