/*
 * Peekopals web app: the full-screen Reels viewer (feed/feedReelsViewerPage.kt, feed/WebAppFeedReel.kt),
 * drawn like the phone's AppFeedReelsView and ReelTextPostPage. Always dark, like the phone's
 * ForceDarkColorScheme: the viewer redefines the theme tokens to the phone's dark ones inside it.
 * - Phones: one reel per screen height, snapped; ✕ and sound at the top right, the author and caption
 *   bottom left over a shade, the rail bottom right. Opened from the Feed, the bottom tabs stay (dark).
 * - Wide screens (900 px and up): the reel is a 9:16 column as tall as the window, centred on black
 *   with the rail beside it and up / down buttons at the right edge, like Instagram's desktop Reels.
 * Loaded on every signed-in page (the cards that open it are on every feed screen).
 */

:root {
    /* the phone's dark Color.kt and Reels colours; the same in light and dark on purpose (the viewer is always dark) */
    --wa-reels-backdrop: #000000;
    --wa-reels-on-media: #FFFFFF;
    --wa-reels-dark-background: #1B1A1A;
    --wa-reels-dark-on-surface: #FFFFFF;
    --wa-reels-dark-on-surface-variant: #D8C2C0;
    --wa-reels-dark-surface: #341010;
    --wa-reels-dark-surface-bright: #522424;
    --wa-reels-dark-surface-dim: #160606;
    --wa-reels-dark-surface-container: #2E1212;
    --wa-reels-dark-surface-container-high: #3D1818;
    --wa-reels-dark-surface-container-highest: #4A2020;
    --wa-reels-dark-outline: #E6E6E6;
    --wa-reels-dark-outline-variant: #524947;
    --wa-reels-dark-inverse-surface: #383838;
    /* Compose's Color.DarkGray at 35% behind the round icons, black 70% at the bottom shade, black 45% over blurred photos */
    --wa-reels-bottom-scrim: rgba(0, 0, 0, 0.7);
    --wa-reels-photo-dim: rgba(0, 0, 0, 0.45);
    --wa-reels-soft-white: rgba(255, 255, 255, 0.7);
    /* the golden text gradient's yellow corner: the secondary yellow at 45% */
    --wa-reels-golden-glow: color-mix(in srgb, var(--md-secondary) 45%, transparent);
}

/* ==================== the viewer ==================== */

.wa-reels-viewer {
    /* the phone's dark scheme for everything inside (the reaction palette, the dots, who reacted) */
    color-scheme: dark;
    --md-background: var(--wa-reels-dark-background);
    --md-on-surface: var(--wa-reels-dark-on-surface);
    --md-on-surface-variant: var(--wa-reels-dark-on-surface-variant);
    --md-surface: var(--wa-reels-dark-surface);
    --md-surface-container: var(--wa-reels-dark-surface-container);
    --md-surface-container-high: var(--wa-reels-dark-surface-container-high);
    --md-surface-container-highest: var(--wa-reels-dark-surface-container-highest);
    --md-outline: var(--wa-reels-dark-outline);
    --md-outline-variant: var(--wa-reels-dark-outline-variant);
    --md-inverse-surface: var(--wa-reels-dark-inverse-surface);
    /* where the top buttons and the bottom controls sit (the phone's insets) */
    --wa-reel-top-inset: env(safe-area-inset-top, 0px);
    --wa-reel-controls-bottom: 8px;

    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--wa-reels-backdrop);
    color: var(--md-on-surface);
    /* the phone's 280 ms fade in, opacity only */
    animation: wa-reels-fade-in 280ms cubic-bezier(0.4, 0, 0.2, 1);
}
/* opened from a pal's Posts tab there are no bottom tabs under it: keep clear of the phone's home bar */
.wa-reels-viewer:not([data-web-picks-home-tab]) { --wa-reel-controls-bottom: calc(8px + var(--wa-bottom-inset)); }
/* ✕: the phone's 240 ms fade out, then back (web-app-feed-reels.js) */
.wa-reels-viewer.is-closing { opacity: 0; transition: opacity 240ms cubic-bezier(0.4, 0, 0.2, 1); }
@keyframes wa-reels-fade-in { from { opacity: 0; } to { opacity: 1; } }
.wa-reels-viewer .wa-mention { color: var(--md-insights); font-weight: 600; }

/* one reel per height, snapped, like the phone's VerticalPager */
.wa-reels-scroller {
    /* the reels' offsetTop counts from here (web-app-feed-reels.js scrolls to them) */
    position: relative;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-snap-type: y mandatory;
    scrollbar-width: none;
    outline: none;
}
.wa-reels-scroller::-webkit-scrollbar { display: none; }
.wa-reel,
.wa-reels-next-page {
    position: relative;
    height: 100%;
    overflow: hidden;
    scroll-snap-align: start;
    scroll-snap-stop: always;
}
.wa-reel--full-rail { --wa-reel-rail-height: 288px; }
.wa-reel--short-rail { --wa-reel-rail-height: 160px; }
.wa-reel-stage {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: var(--wa-reels-backdrop);
    container-type: size;
    container-name: wa-reel-stage;
}

/* bare white icon buttons: ✕ and sound at the top, the rail icons (no circle, so the photo stays clear) */
.wa-reel-round-button,
.wa-reel-rail-circle {
    width: 48px;
    height: 48px;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--wa-reels-on-media);
    cursor: pointer;
}
.wa-reels-viewer .wa-reel-round-button .wa-icon svg,
.wa-reels-viewer .wa-reel-rail-circle .wa-icon svg { width: 24px; height: 24px; }
.wa-reel-round-button:focus-visible { outline: none; box-shadow: var(--wa-focus-ring); }
.wa-reel-top-buttons {
    position: absolute;
    top: calc(var(--wa-reel-top-inset) + 8px);
    right: 8px;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 8px;
}
.wa-reel-sound-button .wa-reel-sound-icon--on { display: none; }
.wa-reel-sound-button.is-sound-on .wa-reel-sound-icon--on { display: inline-flex; }
.wa-reel-sound-button.is-sound-on .wa-reel-sound-icon--off { display: none; }

/* the bottom 42% fades to black 70%, so white words read over any picture */
.wa-reel-bottom-scrim {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    height: 42%;
    background: linear-gradient(to bottom, transparent, var(--wa-reels-bottom-scrim));
    pointer-events: none;
}

/* ==================== bottom left: author and caption ==================== */

.wa-reel-author-and-caption {
    position: absolute;
    left: 0;
    bottom: var(--wa-reel-controls-bottom);
    z-index: 2;
    width: 76%;
    box-sizing: border-box;
    padding: 0 16px;
    color: var(--wa-reels-on-media);
}
.wa-reel-author { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; color: inherit; text-decoration: none; }
a.wa-reel-author:focus-visible { outline: none; box-shadow: var(--wa-focus-ring); border-radius: 999px; }
.wa-reel-author-name {
    font-size: calc(14px * var(--wa-text-scale, 1));
    line-height: calc(20px * var(--wa-text-scale, 1));
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wa-reel-caption {
    margin: 8px 0 0;
    font-size: calc(14px * var(--wa-text-scale, 1));
    line-height: calc(20px * var(--wa-text-scale, 1));
    white-space: pre-line;
    overflow-wrap: anywhere;
}
/* four lines, then "Show more" (web-app-feed-reels.js shows it only when the words are cut off) */
.wa-reel-caption:not(.is-expanded) {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.wa-reel-caption.is-cut-off:not(.is-expanded) { cursor: pointer; }
/* opened, a long caption scrolls instead of running off the top */
.wa-reel-caption.is-expanded { max-height: 40vh; overflow-y: auto; overscroll-behavior: contain; }
.wa-reel-caption-toggle {
    display: block;
    margin: 8px 0 12px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--wa-reels-soft-white);
    font: inherit;
    font-size: calc(14px * var(--wa-text-scale, 1));
    line-height: calc(20px * var(--wa-text-scale, 1));
    font-weight: 600;
    cursor: pointer;
}
.wa-reel-caption-toggle[hidden] { display: none; }

/* ==================== the right rail ==================== */

.wa-reel-rail {
    position: absolute;
    right: 8px;
    bottom: var(--wa-reel-controls-bottom);
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.wa-reel-rail-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--wa-reels-on-media);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}
/* the feed's reaction button, drawn as the rail's icon over its total */
.wa-reel-rail .wa-reaction-summary.wa-reel-rail-button { height: auto; padding: 0; border-radius: 0; overflow: visible; background: none; color: var(--wa-reels-on-media); }
.wa-reel-rail .wa-reaction-summary.wa-reel-rail-button:hover { background: none; }
.wa-reel-rail-button.is-reacted .wa-reel-rail-circle { color: var(--md-primary); }
.wa-reel-rail-button:focus-visible { outline: none; }
.wa-reel-rail-button:focus-visible .wa-reel-rail-circle { box-shadow: var(--wa-focus-ring); }
/* always laid out, invisible at zero, so the rail never jumps when the first one lands */
.wa-reel-rail-count {
    font-size: calc(11px * var(--wa-text-scale, 1));
    line-height: 16px;
    font-weight: 500;
}
.wa-reel-rail-count.is-zero { visibility: hidden; }

/* ==================== a video reel ==================== */

.wa-reel-video-layer { position: absolute; inset: 0; }
.wa-reel-blurred-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(40px);
    /* a little larger, so the blur's soft edge stays outside the reel */
    transform: scale(1.15);
}
.wa-reel-backdrop-dim { position: absolute; inset: 0; background: var(--wa-reels-photo-dim); }
/* 9:16 at the top at full width, never cropped */
.wa-reel-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
    max-height: 100%;
    aspect-ratio: 9 / 16;
    object-fit: contain;
    display: block;
}
/* a reel taller than 9:16: the video's bottom fifth melts into the blurred poster under it */
@container wa-reel-stage (max-aspect-ratio: 9 / 16) {
    .wa-reel-video {
        -webkit-mask-image: linear-gradient(to bottom, black 80%, transparent 100%);
        mask-image: linear-gradient(to bottom, black 80%, transparent 100%);
    }
}

/* ==================== a photo reel ==================== */

/* the square photos across the reel's width, centred, the dots just above them */
.wa-reel-photos-layer { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; }
.wa-reel-photos-box .wa-feed-post-photos { background: transparent; }
.wa-reel-photos-box .wa-feed-post-dots { padding: 0 0 8px; }

/* ==================== a text reel (ReelTextPostPage) ==================== */

/* the gradient is always painted first, over black, so a slow photo never leaves a black screen */
.wa-reel-text-page { position: absolute; inset: 0; overflow: hidden; background-color: var(--wa-reels-backdrop); }
/* wine: soft wine fading to near black */
.wa-reel-text-page--gradient-0 {
    background-image: linear-gradient(to bottom right, var(--wa-reels-dark-surface-bright) 0%, var(--wa-reels-dark-surface) 50%, var(--wa-reels-dark-surface-dim) 100%);
}
/* golden: a yellow glow in the top-left corner melting into wine */
.wa-reel-text-page--gradient-1 {
    background-image: linear-gradient(to bottom right, var(--wa-reels-golden-glow) 0%, var(--wa-reels-dark-surface-bright) 40%, var(--wa-reels-dark-surface-dim) 100%);
}
/* midnight: a band of wine across the middle, dark at both corners */
.wa-reel-text-page--gradient-2 {
    background-image: linear-gradient(to bottom right, var(--wa-reels-dark-surface-dim) 0%, var(--wa-reels-dark-surface-container-highest) 50%, var(--wa-reels-dark-surface-dim) 100%);
}
/* without a photo (none, or it failed to load): the gradient and the round person placeholder */
.wa-reel-text-page.is-without-author-photo :is(.wa-reel-text-backdrop-photo, .wa-reel-text-photo-dim, .wa-reel-text-author-photo) { display: none; }
.wa-reel-text-page:not(.is-without-author-photo) .wa-reel-text-person-placeholder { display: none; }

/* between ✕ (+16px) and the rail (16px above its top); centred both ways, long words scroll inside */
.wa-reel-text-quote-area {
    position: absolute;
    left: 24px;
    right: 24px;
    top: calc(var(--wa-reel-top-inset) + 8px + 48px + 16px);
    bottom: calc(var(--wa-reel-controls-bottom) + var(--wa-reel-rail-height, 288px) + 16px);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
}
.wa-reel-text-quote-area::-webkit-scrollbar { display: none; }
.wa-reel-text-quote { margin: auto 0; display: flex; flex-direction: column; align-items: center; text-align: center; color: var(--md-on-surface); }
.wa-reel-text-author-photo { width: 160px; height: 160px; flex: none; object-fit: cover; border-radius: 24px; }
.wa-reel-text-author-photo--above-words { margin-bottom: 24px; }
/* the phone's DrawCircularImage placeholder: a filled person at half size on a round tile */
.wa-reel-text-person-placeholder {
    width: 160px;
    height: 160px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--md-surface-container-high);
    color: var(--md-on-surface-variant);
}
.wa-reel-text-person-placeholder .wa-icon svg { width: 80px; height: 80px; }
.wa-reel-text-person-placeholder--above-words { margin-bottom: 24px; }
.wa-reel-text-words { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
/* bigger words for shorter posts (up to 80 characters, up to 200, longer) */
.wa-reel-text-words--big {
    font-size: calc(26px * var(--wa-text-scale, 1));
    line-height: calc(36px * var(--wa-text-scale, 1));
    font-weight: 600;
}
.wa-reel-text-words--medium {
    font-size: calc(22px * var(--wa-text-scale, 1));
    line-height: calc(28px * var(--wa-text-scale, 1));
    font-weight: 500;
}
.wa-reel-text-words--small {
    font-size: calc(16px * var(--wa-text-scale, 1));
    line-height: calc(24px * var(--wa-text-scale, 1));
    font-weight: 400;
}

/* ==================== the next page, nothing to show ==================== */

.wa-reels-next-page { display: flex; align-items: center; justify-content: center; }
.wa-reels-next-page-look { width: 100%; height: 100%; border-radius: 0; }
.wa-reels-nothing-to-show {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

/* the up and down buttons are for wide screens; phones swipe */
.wa-reels-step-buttons { display: none; }

/* ==================== phones: the bottom tabs stay under a viewer opened from the Feed ==================== */

@media (max-width: 899px) {
    .wa-app[data-home-tab="none"]:has(> .wa-screen > .wa-app-screen:not([hidden]) .wa-reels-viewer[data-web-picks-home-tab]) > .wa-tab-bar {
        display: flex;
        /* dark while Reels is open, like the phone's bottom bar */
        color-scheme: dark;
        --md-background: var(--wa-reels-dark-background);
        --md-on-surface: var(--wa-reels-dark-on-surface);
        --md-outline-variant: var(--wa-reels-dark-outline-variant);
    }
}

/* ==================== wide screens: a 9:16 column on black, the rail beside it ==================== */

@media (min-width: 900px) {
    .wa-reels-viewer {
        --wa-reel-top-inset: 0px;
        flex: none;
        height: 100dvh;
        position: sticky;
        top: 0;
    }
    .wa-reel {
        display: flex;
        align-items: stretch;
        justify-content: center;
        gap: 16px;
        padding: 16px 0;
        box-sizing: border-box;
    }
    .wa-reel-stage {
        position: relative;
        inset: auto;
        flex: none;
        height: 100%;
        aspect-ratio: 9 / 16;
        border-radius: var(--wa-radius-large);
    }
    /* beside the column, at its bottom */
    .wa-reel-rail { position: static; align-self: flex-end; padding-bottom: var(--wa-reel-controls-bottom); }
    /* the rail is outside the reel: the quote only clears the author row */
    .wa-reel-text-quote-area { bottom: calc(var(--wa-reel-controls-bottom) + 40px + 32px); }
    .wa-reels-next-page { padding: 16px 0; box-sizing: border-box; }
    .wa-reels-next-page-look { width: auto; aspect-ratio: 9 / 16; border-radius: var(--wa-radius-large); }
    .wa-reels-step-buttons {
        position: absolute;
        top: 50%;
        right: 24px;
        z-index: 4;
        display: flex;
        flex-direction: column;
        gap: 12px;
        transform: translateY(-50%);
    }
    .wa-reels-step-button--up .wa-icon { transform: rotate(180deg); }
}

@media (prefers-reduced-motion: reduce) {
    .wa-reels-viewer { animation: none; }
    .wa-reels-viewer.is-closing { transition: none; }
}
