/* This Is Church: Read, Watch, Listen. The copy beside a three-piece carousel of the book, laptop and phone.
   The Read, Watch, Listen links under the copy are the call to action and turn the carousel (home-v2.js). */

.free-chapter {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    align-items: center;
    gap: clamp(1.5rem, 5vw, 4.5rem);
}

.free-chapter__copy {
    align-items: flex-start;
    padding-inline-end: var(--f12-space-5);
}

/* 12px from the heading to the description, like the other large headings; the copy stack's own gap is larger. */
.free-chapter__copy > .f12-stack--xs + :is(.f12-stack--sm, .f12-body) {
    margin-top: calc(var(--f12-space-3) - var(--f12-layout-stack-gap-lg));
}

.free-chapter__copy .f12-body {
    max-width: 47ch;
}

@media (max-width: 640px) {
    .free-chapter { grid-template-columns: minmax(0, 1fr); }
    .free-chapter__copy { padding-inline-end: 0; }
}

/* Phone, with a podcast "now playing" screen built in HTML so it stays sharp at any size. */
.tic-devices__phone {
    position: absolute;
    left: 12cqw;
    bottom: 6cqw;
    z-index: 4;
    width: 18.5cqw;
    aspect-ratio: 9 / 19.2;
    padding: 0.85cqw;
    border-radius: 3.6cqw;
    background: #111;
    box-shadow: 0 0 0 0.3cqw #3a3a3d, 0 3cqw 5cqw rgba(16, 18, 22, 0.28);
    container-type: inline-size;
}

.tic-devices__player {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 26cqw 8cqw 0;
    overflow: hidden;
    border-radius: 13cqw;
    background: linear-gradient(180deg, #3b3b3b 0%, #1a1a1a 55%, #0e0e0e 100%);
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}

.tic-devices__island {
    position: absolute;
    top: 4.5cqw;
    left: 50%;
    width: 32cqw;
    height: 9cqw;
    border-radius: 9cqw;
    background: #000;
    transform: translateX(-50%);
}

.tic-devices__art {
    width: 100%;
    height: auto;
    border-radius: 5cqw;
    box-shadow: 0 6cqw 12cqw rgba(0, 0, 0, 0.45);
}

.tic-devices__track {
    display: grid;
    gap: 1.5cqw;
    margin-top: 10cqw;
}

.tic-devices__episode {
    font-size: 7.4cqw;
    font-weight: 700;
    line-height: 1.15;
}

.tic-devices__show {
    color: rgba(255, 255, 255, 0.6);
    font-size: 6cqw;
}

.tic-devices__progress {
    display: block;
    height: 1.6cqw;
    margin-top: 8cqw;
    border-radius: 2cqw;
    background: rgba(255, 255, 255, 0.22);
}

.tic-devices__progress span {
    display: block;
    width: 27%;
    height: 100%;
    border-radius: inherit;
    background: rgba(255, 255, 255, 0.85);
}

.tic-devices__times {
    display: flex;
    justify-content: space-between;
    margin-top: 2cqw;
    color: rgba(255, 255, 255, 0.5);
    font-size: 4.8cqw;
}

.tic-devices__controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12cqw;
    padding-inline: 4cqw;
}

.tic-devices__controls svg { width: 13cqw; height: 13cqw; }
.tic-devices__controls .tic-devices__pause { width: 18cqw; height: 18cqw; }

/* Light: Read, Watch, Listen. A three-piece carousel: the book, laptop and phone are always on show.
   The focused one stands large in the middle; the other two wait smaller at the sides, and it turns
   like a carousel. Every piece is centred on the stage, and sizes are in cqw of the stage so it scales
   as one piece. The eyebrow is three small buttons; the active one is red with the soft button's line
   under it, which fills while the section plays on its own. */
.free-chapter--formats {
    --tic-interval: 4200ms;
    --tic-ease: cubic-bezier(0.65, 0, 0.35, 1);
    --tic-speed: 850ms;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); /* Even halves, so the copy runs wider. */
    align-items: center;
    column-gap: var(--f12-space-6); /* The stage already has air at its sides, so the gap can be small. */
}

.free-chapter--formats .free-chapter__copy .f12-body { max-width: 58ch; }

.tic-formats__stage {
    position: relative;
    container-type: inline-size;
    width: min(640px, 100%);
    aspect-ratio: 1 / 0.5; /* Just tall enough for the book, the tallest piece, so the section has no extra air above. */
    margin-inline: auto 0; /* Hugs the copy on wide screens. */
    touch-action: pan-y; /* Sideways swipes turn the carousel; up and down still scrolls the page. */
}

.tic-formats__item {
    --x: 0cqw;
    --scale: 1;
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 3;
    width: var(--w);
    transform: translate(calc(-50% + var(--x)), -50%) scale(var(--scale)); /* Centred both ways on the stage. */
    transition: transform var(--tic-speed) var(--tic-ease), opacity var(--tic-speed) var(--tic-ease), filter var(--tic-speed) var(--tic-ease);
    cursor: pointer;
    user-select: none;
    -webkit-user-drag: none;
}

/* Each piece's size when it has focus, balanced by eye. */
.tic-formats__item[data-tic-format="read"] { --w: 40cqw; }
.tic-formats__item[data-tic-format="watch"] { --w: 60cqw; }
.tic-formats__item[data-tic-format="listen"] { --w: 23cqw; }

.tic-formats__item[data-pos="center"] { cursor: default; }

.tic-formats__item:is([data-pos="left"], [data-pos="right"]) {
    --scale: 0.32;
    z-index: 1;
    opacity: 0.5;
    filter: blur(2px) saturate(0.6); /* Slightly out of focus, so the eye goes to the middle. */
}

/* The side pieces sit just past the focused piece's edge, so the gap stays tight whichever is in focus. */
.tic-formats__stage[data-focus="read"] { --side-x: 29cqw; }
.tic-formats__stage[data-focus="watch"] { --side-x: 36cqw; }
.tic-formats__stage[data-focus="listen"] { --side-x: 24cqw; }

.tic-formats__item[data-pos="left"] { --x: calc(-1 * var(--side-x, 33cqw)); }
.tic-formats__item[data-pos="right"] { --x: var(--side-x, 33cqw); }

.tic-formats__item:is([data-pos="left"], [data-pos="right"]):hover {
    --scale: 0.35;
    opacity: 0.8;
    filter: none;
}

/* The piece that wraps round the back fades out and in, so it never crosses in front. */
.tic-formats__item.is-wrapping {
    z-index: 0;
    animation: tic-formats-wrap var(--tic-speed) var(--tic-ease);
}

@keyframes tic-formats-wrap {
    40%, 60% { opacity: 0; }
}

/* The book and laptop renders are JPGs on white. Multiply drops the white, so they stay clean on any light
   background and pieces behind them show through. It sits on the piece, not the img: the piece's transform
   would otherwise isolate the img and leave the white box in place. Swap for transparent images when we have them. */
.tic-formats__item:is([data-tic-format="read"], [data-tic-format="watch"]) { mix-blend-mode: multiply; }

.tic-formats__item > img {
    display: block;
    width: 100%;
    max-width: none;
    height: auto;
    pointer-events: none;
}

.tic-formats__item .tic-devices__phone {
    display: block; /* A span: it must be a block to be the size container its screen is drawn in. */
    position: relative;
    left: auto;
    bottom: auto;
    width: 100%;
}

/* The title changes with each step and eases in. */
.free-chapter--formats [data-tic-title-text].is-changing { animation: tic-formats-title 450ms ease both; }

@keyframes tic-formats-title {
    from { opacity: 0; transform: translateY(6px); }
}

@media (prefers-reduced-motion: reduce) {
    .free-chapter--formats [data-tic-title-text].is-changing { animation: none; }
}

/* Read, Watch, Listen: the call to action under the copy. The active one is red with the soft button's line. */
.tic-formats__tabs {
    --tic-tab-gap: var(--f12-space-5);
    display: flex;
    align-items: center;
    gap: var(--tic-tab-gap);
}

.tic-formats__tab {
    position: relative;
    padding: var(--f12-space-2) 0;
    border: 0;
    background: none;
    color: var(--f12-color-text-muted);
    font: inherit;
    font-size: var(--f12-font-size-xs);
    font-weight: var(--f12-font-weight-bold);
    letter-spacing: var(--f12-letter-spacing-caps);
    line-height: var(--f12-line-height-tight);
    text-decoration: none;
    text-transform: uppercase;
    cursor: pointer;
    transition: color 200ms ease;
}

.tic-formats__tab + .tic-formats__tab::before {
    content: "";
    position: absolute;
    top: 50%;
    left: calc(-0.5 * var(--tic-tab-gap) - 2px);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--f12-color-border-subtle);
    transform: translateY(-50%);
}

.tic-formats__tab:hover { color: var(--f12-color-text-heading); }
.tic-formats__tab[aria-current="true"] { color: var(--f12-color-brand-editorial); }

.tic-formats__tab::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 2px;
    background: var(--f12-color-brand-editorial);
    transform: scaleX(0);
    transform-origin: left;
}

.tic-formats__tab[aria-current="true"]::after { transform: none; }

.free-chapter--formats.is-autoplay .tic-formats__tab[aria-current="true"]::after {
    animation: tic-formats-fill var(--tic-interval) linear both;
}

.free-chapter--formats.is-paused .tic-formats__tab[aria-current="true"]::after { animation-play-state: paused; }

@keyframes tic-formats-fill {
    from { transform: scaleX(0); }
    to { transform: none; }
}

@media (max-width: 1024px) {
    .free-chapter--formats { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

@media (max-width: 640px) {
    .free-chapter--formats { grid-template-columns: minmax(0, 1fr); }
    .free-chapter--formats .tic-formats__stage { order: 1; } /* Copy first, then the pieces, so the links lead into them. */
    .tic-formats__stage { width: min(440px, 100%); aspect-ratio: 1 / 0.54; margin-inline: auto; }
    .tic-formats__stage[data-focus="read"] { --side-x: 31cqw; }
    .tic-formats__stage[data-focus="watch"] { --side-x: 37cqw; }
    .tic-formats__stage[data-focus="listen"] { --side-x: 26cqw; }
    /* A touch larger on phones, where the stage is narrow. */
    .tic-formats__item[data-tic-format="read"] { --w: 44cqw; }
    .tic-formats__item[data-tic-format="watch"] { --w: 64cqw; }
    .tic-formats__item[data-tic-format="listen"] { --w: 25cqw; }
}

@media (prefers-reduced-motion: reduce) {
    .free-chapter--formats { --tic-speed: 0s; }
}

/* Carousel mirror: a faint reflection under each piece, as if it stands on a glossy floor. The book and
   laptop images are cropped to end where the object ends, so the reflection starts right at its base.
   Chrome and Safari only; other browsers simply show no reflection. */
.tic-formats__item > img,
.tic-formats__item .tic-devices__phone {
    -webkit-box-reflect: below 1px linear-gradient(transparent 70%, rgba(0, 0, 0, 0.16));
}

/* Mobile alignment standard: centre the links under the centred copy. */
@media (max-width: 768px) {
    .tic-formats__tabs { justify-content: center; }
}
