/* Clip swipe feed. One clip per screen, snap-scrolled.

   Compositing rule for anything that can hold a pool <video>: no
   display:none, visibility:hidden, opacity:0 or content-visibility on the
   slide, the stage or the video itself. Browsers stop painting those, and a
   video that has not painted is the black flash between clips. Off-screen
   means scrolled out of view, nothing else. Only the still above the video
   fades. */

html.clip-feed-lock,
html.clip-feed-lock body {
    overflow: hidden;
    overscroll-behavior: none;
}

.clip-feed {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: #000;
    color: #fff;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.clip-feed[hidden] {
    display: none;
}

.clip-feed:focus {
    outline: none;
}

/* The watch page keeps the site header above the feed. */
.clip-feed--page {
    top: 60px;
    z-index: 50;
}

.clip-feed__scroller {
    position: relative;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-snap-type: y mandatory;
    overscroll-behavior: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.clip-feed__scroller::-webkit-scrollbar {
    display: none;
}

.clip-feed__slide {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    scroll-snap-align: start;
    /* A trackpad flick or a hard swipe stops at the next clip, never past it. */
    scroll-snap-stop: always;
    /* Each slide on its own layer, so the video is not re-rastered mid-scroll. */
    transform: translateZ(0);
}

.clip-feed__stage {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
}

@media (min-width: 768px) {
    .clip-feed__stage {
        width: auto;
        height: calc(100% - 32px);
        aspect-ratio: 9 / 16;
        max-width: calc(100vw - 180px);
        border-radius: 14px;
    }
}

/* Video and still share one box and one crop, so the handover cannot shift
   or reframe the picture. */
.clip-feed__video,
.clip-feed__still {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

.clip-feed__video {
    z-index: 0;
}

.clip-feed__still {
    z-index: 1;
    pointer-events: none;
    user-select: none;
    transition: opacity 120ms linear;
}

.clip-feed__still:not([src]) {
    background: #0b0b0f;
}

.clip-feed__still.is-blur {
    filter: blur(18px);
    transform: scale(1.12);
}

/* Primed: the video below is already showing frame zero. */
.clip-feed__slide.is-primed .clip-feed__still {
    opacity: 0;
}

.clip-feed__boot {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
}

.clip-feed__tap {
    position: absolute;
    inset: 0;
    z-index: 2;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
}

.clip-feed__tap:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.7);
    outline-offset: -4px;
}

.clip-feed__paused {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 3;
    width: 72px;
    height: 72px;
    margin: -36px 0 0 -36px;
    padding: 20px 18px 20px 22px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.42);
    color: #fff;
    pointer-events: none;
    opacity: 0;
    transform: scale(0.85);
    transition: opacity 160ms ease, transform 160ms ease;
}

.clip-feed__paused svg {
    display: block;
    width: 100%;
    height: 100%;
}

.clip-feed__slide.is-paused .clip-feed__paused {
    opacity: 1;
    transform: scale(1);
}

/* An unprimed active slide shows the spinner only after 400ms, so a start
   that is merely a few frames late never flashes one. */
.clip-feed__spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 3;
    width: 38px;
    height: 38px;
    margin: -19px 0 0 -19px;
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 120ms linear;
    animation: clip-feed-spin 0.8s linear infinite;
}

.clip-feed__slide.is-active:not(.is-primed):not(.has-error) .clip-feed__spinner,
.clip-feed__slide.is-buffering .clip-feed__spinner {
    opacity: 1;
    transition-delay: 400ms;
}

.clip-feed__slide.is-buffering .clip-feed__spinner {
    transition-delay: 0ms;
}

@keyframes clip-feed-spin {
    to { transform: rotate(360deg); }
}

.clip-feed__error {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    background: rgba(0, 0, 0, 0.55);
    text-align: center;
}

.clip-feed__slide.has-error .clip-feed__error {
    display: flex;
}

.clip-feed__error p {
    margin: 0;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.85);
}

.clip-feed__retry,
.clip-feed__cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 22px;
    border: 0;
    border-radius: 999px;
    background: #e8385a;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.clip-feed__retry:hover,
.clip-feed__cta:hover {
    background: #f04a6b;
    color: #fff;
}

/* --- Meta and actions --------------------------------------------------- */

.clip-feed__meta {
    position: absolute;
    right: 76px;
    bottom: 22px;
    left: 0;
    z-index: 3;
    padding: 48px 16px 0;
    pointer-events: none;
}

.clip-feed__stage::after {
    content: '';
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 2;
    height: 42%;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.62), transparent);
    pointer-events: none;
}

.clip-feed__creator {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    color: #fff;
    text-decoration: none;
    pointer-events: auto;
}

a.clip-feed__creator:hover .clip-feed__handle {
    text-decoration: underline;
}

.clip-feed__avatar {
    width: 36px;
    height: 36px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    object-fit: cover;
}

.clip-feed__handle {
    font-size: 15px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.clip-feed__title {
    display: -webkit-box;
    margin: 8px 0 0;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.4;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.clip-feed__chip {
    display: inline-block;
    margin-top: 8px;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    font-size: 11.5px;
    letter-spacing: 0.02em;
}

.clip-feed__actions {
    position: absolute;
    right: 10px;
    bottom: 30px;
    z-index: 3;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.clip-feed__action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 0;
    border: 0;
    background: none;
    color: #fff;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
}

.clip-feed__action svg {
    width: 46px;
    height: 46px;
    padding: 11px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.36);
}

.clip-feed__progress {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 3;
    height: 3px;
    background: rgba(255, 255, 255, 0.18);
    pointer-events: none;
}

.clip-feed__progress span {
    display: block;
    height: 100%;
    background: #fff;
    transform: scaleX(0);
    transform-origin: left center;
}

.clip-feed__debug {
    position: absolute;
    top: 64px;
    left: 10px;
    z-index: 5;
    margin: 0;
    padding: 6px 8px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.7);
    color: #7cfc9a;
    font: 11px/1.4 ui-monospace, Menlo, monospace;
    white-space: pre;
    pointer-events: none;
}

/* --- Chrome ------------------------------------------------------------- */

.clip-feed__chrome {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    z-index: 6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: max(12px, env(safe-area-inset-top)) 14px 12px;
    pointer-events: none;
}

.clip-feed__chrome > * {
    pointer-events: auto;
}

.clip-feed__icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.42);
    color: #fff;
    font-size: 17px;
    cursor: pointer;
}

.clip-feed__icon-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.clip-feed__icon-btn svg {
    width: 20px;
    height: 20px;
}

.clip-feed__mute .clip-feed__icon-muted { display: none; }
.clip-feed__mute.is-muted .clip-feed__icon-muted { display: block; }
.clip-feed__mute.is-muted .clip-feed__icon-sound { display: none; }

.clip-feed__sound-pill {
    position: absolute;
    top: max(64px, calc(env(safe-area-inset-top) + 52px));
    left: 50%;
    z-index: 6;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 14px;
    border: 1px solid rgba(232, 56, 90, 0.55);
    border-radius: 999px;
    background: rgba(20, 8, 12, 0.72);
    color: #ffd9df;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transform: translateX(-50%);
}

.clip-feed__sound-pill[hidden] {
    display: none;
}

.clip-feed__nav {
    position: absolute;
    top: 50%;
    right: 26px;
    z-index: 6;
    display: none;
    flex-direction: column;
    gap: 12px;
    transform: translateY(-50%);
}

@media (min-width: 768px) and (hover: hover) {
    .clip-feed__nav {
        display: flex;
    }
}

/* --- Gate and end panels ------------------------------------------------ */

.clip-feed__panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    width: min(420px, 88vw);
    padding: 34px 26px;
    border-radius: 18px;
    background: radial-gradient(circle at 20% 0%, rgba(111, 45, 189, 0.32), transparent 55%), #121217;
    text-align: center;
}

.clip-feed__panel-title {
    margin: 0;
    font-size: 21px;
    line-height: 1.3;
    color: #fff;
}

.clip-feed__panel-sub {
    margin: 0;
    font-size: 13.5px;
    color: rgba(255, 255, 255, 0.62);
}

.clip-feed__panel-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
}

.clip-feed__link {
    padding: 6px 10px;
    border: 0;
    background: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 13.5px;
    text-decoration: underline;
    cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
    .clip-feed__still,
    .clip-feed__paused,
    .clip-feed__spinner {
        transition: none;
    }
}
