/* Carousel: sheet carousel (carousel- prefix) and the comic heading above it (comic- prefix). */


/* Carousel */

.carousel {
    padding-top: 60px;
    position: relative;
    text-align: center;
}

/* Row: previous arrow, framed viewport, next arrow. */
.carousel-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
    margin-bottom: 24px;
}

/* In a project panel the row is capped so the arrows stay away from the screen edges. */
.panel .carousel-row {
    max-width: 1300px;
    margin: 0 auto;
}

.carousel-row .frame-wrap {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
}

.carousel--landscape .carousel-row .frame-wrap {
    width: 100%;
    max-width: var(--content-max);
    max-height: 65vh;
    aspect-ratio: var(--a4) / 1;
}

/* Portrait A4 sheet. The width is capped so that sheet plus controls (143px: header, gaps,
   dots) fit a short window; the cap only bites below about 737px of height. */
.carousel-viewport {
    width: min(420px, max(120px, calc((100vh - var(--carousel-chrome)) / var(--a4))));
    width: min(420px, max(120px, calc((100dvh - var(--carousel-chrome)) / var(--a4))));
    aspect-ratio: 1 / var(--a4);
    overflow: hidden;
    position: relative;
    border-radius: 4px;
}

/* Landscape board: it fills the frame, which carries the ratio. No forced height: Safari does
   not treat a height that comes from an aspect-ratio bounded by max-height as definite, and a
   height of 100% would fall back to the image's natural height. As a stretched flex child the
   viewport follows the frame in every engine. */
.carousel--landscape .carousel-viewport {
    width: 100%;
    max-width: 100%;
    aspect-ratio: auto;
    margin: 0 auto;
    box-shadow: 10px 10px 30px rgb(0 0 0 / 60%);
    border-radius: 8px;
    background: var(--white);
    align-self: stretch;
}

.panel--alt .carousel-viewport { box-shadow: 8px 8px 24px rgb(0 0 0 / 18%); }

/* The red rectangle sits exactly on the viewport, not on the wider frame-wrap. */
.sketch-rect-svg--carousel {
    top: -3%;
    left: -3%;
    width: 106%;
    height: 106%;
    transition: opacity 0.2s ease;
}

.carousel-track {
    width: 100%;
    height: 100%;
    position: relative;
}

/* Slides are stacked; only the active one shows and takes pointer events. */
.carousel-slide {
    position: absolute;
    inset: 0;
    opacity: 0;
    transform: scale(0.96) translateY(10px);
    transition: opacity 0.6s var(--ease-soft), transform 0.6s var(--ease-soft);
    pointer-events: none;
    z-index: 1;
}

.carousel-slide.is-active {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
    z-index: 2;
}

.carousel-slide .drawing-sheet-wrap,
.carousel-slide .media-frame-inner {
    width: 100%;
    height: 100%;
}

.carousel-slide .drawing-sheet-wrap { transition: transform var(--dur-base) ease, box-shadow var(--dur-base) ease; }
.carousel-slide.is-active .drawing-sheet-wrap { cursor: zoom-in; }

.carousel-slide .drawing-sheet-wrap:hover {
    transform: scale(1.02);
    box-shadow: 15px 15px 40px rgb(0 0 0 / 50%);
}

.carousel-arrow {
    position: relative;
    z-index: 20;
    color: var(--white);
    width: 54px;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--dur-base) ease, transform var(--dur-base) var(--ease-soft);
}

.carousel-arrow:hover {
    color: var(--red);
    transform: scale(1.15) rotate(-5deg);
}

/* On the anthracite panel the hovered arrow sits on a white square. */
.panel--alt .carousel-arrow:hover { background: var(--white); }

/* Touch targets: a transparent pseudo-element enlarges the hit area only (44x44 minimum), the
   drawing stays the same. */
.carousel-arrow::after,
.carousel-toggle::after {
    content: '';
    position: absolute;
    inset: -10px;
}

/* The arrow is drawn three times; the strokes show in turn, like a three-frame flipbook. */
.sketch-frame-1,
.sketch-frame-2,
.sketch-frame-3 {
    animation: frame-toggle 0.45s infinite;
}

.sketch-frame-2 { animation-delay: 0.15s; }
.sketch-frame-3 { animation-delay: 0.3s; }

/* Controls of the comic carousel: play or pause, dots, timer, counter. */
.carousel-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    margin-top: 28px;
}

.carousel-toggle {
    position: relative;
    color: var(--white);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--dur-base) ease, transform 0.2s ease;
}

.carousel-toggle:hover {
    color: var(--red);
    transform: scale(1.15);
}

/* Autoplay switched off: the play icon replaces the pause icon. */
.icon-play { display: none; }
.carousel-toggle.is-paused .icon-pause { display: none; }
.carousel-toggle.is-paused .icon-play { display: block; }

.carousel-dots {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Dots are buttons: native look and font size are reset. */
.carousel-dot {
    -webkit-appearance: none;
    appearance: none;
    font-size: inherit;
    position: relative;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgb(255 255 255 / 25%);
    cursor: pointer;
    transition: all var(--dur-base) ease;
}

.carousel-dot.is-active {
    background: var(--red);
    transform: scale(1.3);
}

/* Time left before the next slide; the script drives the bar width. */
.carousel-timer {
    width: 180px;
    height: 4px;
    background: rgb(255 255 255 / 10%);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.carousel-timer-bar {
    width: 0%;
    height: 100%;
    background: var(--red);
}

.carousel-controls .carousel-counter {
    font-size: 1.3rem;
    color: var(--muted);
    min-width: 50px;
    text-align: right;
}

/* Footer of the project-page carousels: counter and progress bar. */
.carousel-footer {
    z-index: 20;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    max-width: var(--content-max);
    width: 100%;
    margin: 30px auto 0;
    padding: 0 10px 60px;
}

.carousel-footer .carousel-counter {
    font-family: var(--font-sketch);
    font-size: 1.5rem;
    color: var(--white);
    letter-spacing: 2px;
}

.panel--alt .carousel-counter { font-weight: bold; }

.carousel-progress {
    flex: 1;
    height: 6px;
    background: rgb(255 255 255 / 10%);
    margin-left: 30px;
    border-radius: 3px;
    position: relative;
    overflow: hidden;
}

.panel--alt .carousel-progress { background: rgb(255 255 255 / 15%); }

.carousel-progress-bar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 0%;
    background: var(--red);
    transition: width 0.1s linear;
}

@media (min-width: 992px) and (max-width: 1365px) {
    /* Mid-size screens: the board gives up the width the two arrows need, so they stay inside
       the viewport. */
    .carousel--landscape .carousel-row .frame-wrap {
        flex: 0 1 auto;
        min-width: 0;
    }
}

@media (max-width: 768px) {
    .carousel-row { gap: 10px; }
    .carousel--landscape .carousel-row .frame-wrap { max-height: 50vh; }

    /* The sheet takes the width left once the arrows and their gaps are deducted. */
    .carousel-viewport {
        width: min(320px, calc(100vw - 92px), max(120px, calc((100vh - var(--carousel-chrome)) / var(--a4))));
        width: min(320px, calc(100vw - 92px), max(120px, calc((100dvh - var(--carousel-chrome)) / var(--a4))));
    }

    .carousel-arrow {
        width: 44px;
        height: 44px;
    }

    .carousel-timer { width: 80px; }

    /* Project-page carousels: the arrows move to the footer row, on the plain background, where
       they do not blend into the drawing. Anchored on .carousel-row because its height follows
       the board; top: calc(100% + 48px) centres each arrow on the counter. Same weight as the
       hover rule and declared after it: no hover transform here. */
    .panel .carousel-row { position: relative; }

    .panel .carousel-arrow {
        position: absolute;
        top: calc(100% + 48px);
        transform: translateY(-50%);
        z-index: 25;
    }

    .panel .carousel-arrow--prev { left: 0; }
    .panel .carousel-arrow--next { right: 0; }

    /* Inset 56px each side so that counter and progress bar pass clear of the arrows. */
    .carousel-footer {
        padding-left: 56px;
        padding-right: 56px;
        gap: 12px;
    }

    .carousel-progress { margin-left: 0; }
}

@media (hover: none), (pointer: coarse) {
    /* The dots are 22px apart centre to centre. Widening their hit area as they stand would
       make them overlap and tap the neighbouring slide: they are spread first, then each area
       extends to half the new gap, less a 2px guard. */
    .carousel-dots { gap: 30px; }

    .carousel-dot::after {
        content: '';
        position: absolute;
        inset: -14px -13px;
    }
}

@keyframes frame-toggle {
    0%, 33.32% { opacity: 1; }
    33.33%, 100% { opacity: 0; }
}


/* Comic heading */

.comic-heading {
    position: relative;
    text-align: center;
    margin-bottom: 5px;
    z-index: 2;
    pointer-events: none;
}

.comic-kicker {
    font-size: clamp(1.8rem, 3.5vw, 2.8rem);
    font-weight: bold;
    color: var(--white);
    letter-spacing: 0.05em;
    transform: translateY(18px) rotate(-4deg);
    display: inline-block;
    position: relative;
    z-index: 15;
}

.comic-title {
    font-family: var(--font-display);
    font-size: clamp(3.8rem, 12vw, 9.8rem);
    font-weight: bold;
    line-height: 0.75;
    letter-spacing: -0.01em;
    color: var(--red);
    text-transform: uppercase;
    display: block;
    position: relative;
    z-index: 10;
    cursor: default;
    pointer-events: auto;
}

/* Explosion played frame by frame from one sprite while the title is hovered. */
.comic-burst {
    position: absolute;
    bottom: -40px;
    left: 50%;
    margin-left: -285px;
    width: 150px;
    height: 150px;
    background-image: url('../assets/comic-burst-sprite.svg');
    background-size: 500% 100%;
    background-position: 0 0;
    transform-origin: 50% 100%;
    transform: rotate(-45deg) scale(1.15);
    opacity: 0;
    pointer-events: none;
    z-index: 20;
}

.comic-title:hover ~ .comic-burst {
    opacity: 1;
    animation: comic-burst 0.6s steps(4) forwards;
}

@media (max-width: 991px) {
    /* The burst is rotated 45deg: its bounding box overflows by width x 0.207 on each side
       (measured: 38px), so the left margin must exceed that or it sticks out of the page. */
    .comic-burst {
        left: 0;
        margin-left: 44px;
        width: 120px;
        height: 120px;
    }
}

@media (max-width: 768px) {
    .comic-kicker {
        font-size: 1.6rem;
        margin-bottom: 20px;
    }

    .comic-burst { bottom: -20px; }
}

@media (max-width: 480px) {
    /* Proportional overflow: about 30px per side. */
    .comic-burst {
        width: 96px;
        height: 96px;
        margin-left: 36px;
        bottom: -24px;
    }
}

@keyframes comic-burst {
    from { background-position: 0% 0; }
    to { background-position: 100% 0; }
}
