/*
 * Thames Herald Page Turner v0.5.0
 *
 * The browser viewport is locked against horizontal swipe/overscroll.
 * Only the central .th-newspaper sheet interprets horizontal gestures.
 */

/* Stop the browser/page shell itself moving sideways. */
html,
body {
    overflow-x: hidden;
    overscroll-behavior-x: none;
}

.th-site-shell {
    overflow-x: clip;
    overscroll-behavior-x: none;
}

/*
 * The newspaper can still scroll vertically, but horizontal touch movement
 * is handled by the Page Turner script rather than by the browser viewport.
 */
.th-newspaper {
    touch-action: pan-y;
    overscroll-behavior-x: none;
    will-change: transform;
    backface-visibility: hidden;
}

.thpt-nav {
    position: fixed;
    inset: 0;
    z-index: 9990;
    pointer-events: none;
}

.thpt-edge {
    position: fixed;
    top: var(--thpt-page-top, 0px);
    height: var(--thpt-page-height, 100vh);
    width: 38px;
    pointer-events: auto;
    text-decoration: none;
    outline: none;
    overflow: visible;
}

.thpt-edge--prev {
    left: var(--thpt-page-left, 0px);
}

.thpt-edge--next {
    left: calc(var(--thpt-page-right, 100vw) - 38px);
}

/*
 * Thames Herald Page Turner v1.6 exact 45-degree fold.
 *
 * Construction:
 * 1. draw a 45-degree axis across the page corner;
 * 2. reflect the original outside corner across that fixed axis;
 * 3. render the reflected triangle as the folded-back flap.
 *
 * Hidden by default and revealed only by hover/near-edge interaction.
 */

.thpt-edge::before {
    content: none !important;
}

.thpt-curl {
    position: absolute;
    top: 0;
    width: 42px;
    height: 42px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    overflow: visible;
    z-index: 3;
    transform: scale(.92);
    transition:
        opacity .13s ease,
        visibility .13s ease,
        transform .16s ease,
        filter .16s ease;
}

.thpt-curl--prev {
    left: 0;
    transform-origin: top left;
}

.thpt-curl--next {
    right: 0;
    transform-origin: top right;
}

/* The next sheet visible where the top corner has folded away. */
.thpt-curl-reveal {
    fill: var(--thpt-page-bg, #f6f1e5);
    stroke: rgba(165,162,154,.16);
    stroke-width: .35;
}

/* Soft cast shadow behind the lifted reflected triangle. */
.thpt-curl-cast-shadow {
    fill: rgba(0,0,0,.18);
}

/* The mirrored corner itself. */
.thpt-curl-flap {
    stroke: rgba(180,177,168,.48);
    stroke-width: .5;
}

/* Darker narrow shadow directly under the fold axis. */
.thpt-curl-contact-shadow {
    fill: none;
    stroke: rgba(0,0,0,.30);
    stroke-width: 1.5;
}

/* Fixed 45-degree fold line. */
.thpt-curl-crease {
    fill: none;
    stroke: rgba(92,89,84,.28);
    stroke-width: .55;
}

/* Reveal only on deliberate interaction. */
.thpt-edge:hover .thpt-curl,
.thpt-edge:focus-visible .thpt-curl,
.thpt-edge.is-near .thpt-curl {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
    filter: drop-shadow(0 2px 3px rgba(0,0,0,.10));
}

/* Subtle shadow only on the newspaper edge. */
.thpt-edge::after {
    content: "";
    position: absolute;
    z-index: 2;
    top: 0;
    bottom: 0;
    width: 18px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
}

.thpt-edge--prev::after {
    left: 0;
    background: linear-gradient(to right, rgba(0,0,0,.075), transparent);
}

.thpt-edge--next::after {
    right: 0;
    background: linear-gradient(to left, rgba(0,0,0,.075), transparent);
}

.thpt-edge:hover::after,
.thpt-edge:focus-visible::after,
.thpt-edge.is-near::after {
    opacity: 1;
}

/*
 * Only the central newspaper sheet turns.
 * No translateX is used, so the surrounding shell stays visually anchored.
 */
html.thpt-turning-next .th-newspaper {
    transform-origin: left center;
    animation: thpt-sheet-next .22s cubic-bezier(.3,.1,.5,1) forwards;
}

html.thpt-turning-prev .th-newspaper {
    transform-origin: right center;
    animation: thpt-sheet-prev .22s cubic-bezier(.3,.1,.5,1) forwards;
}

@keyframes thpt-sheet-next {
    0% {
        transform: perspective(1600px) rotateY(0deg);
        filter: brightness(1);
    }
    100% {
        transform: perspective(1600px) rotateY(-9deg);
        filter: brightness(.94);
    }
}

@keyframes thpt-sheet-prev {
    0% {
        transform: perspective(1600px) rotateY(0deg);
        filter: brightness(1);
    }
    100% {
        transform: perspective(1600px) rotateY(9deg);
        filter: brightness(.94);
    }
}

@media (prefers-reduced-motion: reduce) {
    .thpt-curl,
    .thpt-edge::after,
    html.thpt-turning-next .th-newspaper,
    html.thpt-turning-prev .th-newspaper {
        transition: none !important;
        animation: none !important;
    }
}

@media (max-width: 700px) {
    .thpt-edge {
        width: 24px;
    }

    .thpt-edge--next {
        left: calc(var(--thpt-page-right, 100vw) - 24px);
    }

    .thpt-curl {
        width: 40px;
        height: 40px;
    }

    .thpt-edge::before {
        width: 28px;
        height: 28px;
    }
}
