/*
 * FapSwipe Native Player media stage + interaction surface.
 *
 * Version 0.10.0 adds selectable feed skins on top of the stable Fit + gesture stage. The stage owns
 * geometry while the <video> remains the browser's native decoding surface.
 * object-fit:contain is deliberate: FapSwipe never crops source composition by
 * default. Future zoom/fill modes can transform this same media surface without
 * changing the stored source or recreating the video element.
 */
.fapswipe-native-stage {
    position: relative;
    max-width: 100%;
    line-height: 0;
}

.fapswipe-native-stage .fapswipe-native-video {
    display: block;
    max-width: 100%;
    max-height: 100dvh;
}

/*
 * FEED MEDIA STAGE
 * ----------------
 * Portrait/default view deliberately leaves breathing room for FapSwipe's
 * title/actions. The JS controller writes a VisualViewport-derived pixel value
 * when available so mobile browser chrome changes do not leave us sizing from a
 * stale layout viewport. 72dvh is the zero-JS fallback.
 */
.fapswipe-native-stage[data-fapswipe-surface="feed"] {
    box-sizing: border-box;
    display: grid;
    place-items: center;
    width: calc(100% - 24px);
    height: min(var(--fapswipe-native-portrait-stage-height, 72dvh), 760px);
    margin-inline: auto;
    overflow: hidden;
    background: #000;
}

.fapswipe-native-stage[data-fapswipe-surface="feed"] .fapswipe-native-video {
    /*
     * JS writes the exact contained pixel rectangle from the stage + decoded
     * media dimensions. auto/max fallbacks keep the video sane before metadata
     * is available. This avoids theme/browser rules stretching a portrait
     * replaced element into a landscape box.
     */
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center center;
}

/*
 * Phone/tablet landscape is the useful exception to the portrait breathing-room
 * rule. A short landscape viewport should behave more like a media viewer: use
 * almost all available visual height and let contain-fit decide the final video
 * rectangle. Safe-area insets protect notches/rounded corners without requiring
 * device-specific JavaScript.
 */
@media (orientation: landscape) and (max-height: 600px) {
    .fapswipe-native-stage[data-fapswipe-surface="feed"] {
        width: calc(
            100% - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px) - 8px
        );
        height: calc(
            var(--fapswipe-native-viewport-height, 100dvh)
            - env(safe-area-inset-top, 0px)
            - env(safe-area-inset-bottom, 0px)
            - 8px
        );
        max-height: none;
    }
}

/*
 * /watch/ remains intentionally conventional in this release. It keeps native
 * controls and its previous sizing behavior; the Fit stage is a feed concern
 * until we have finished testing the media interaction model.
 */
.fapswipe-native-stage[data-fapswipe-surface="single"] .fapswipe-native-video {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100dvh;
}

.fapswipe-native-stage[data-fapswipe-feed-interaction="1"] {
    cursor: pointer;
    /*
     * Gesture ownership is intentionally local to the media stage. At 1x the
     * pointer stream still bubbles to vertical Swiper; with two contacts Native
     * Player performs media pinch zoom; above 1x one contact pans the media.
     * This does not disable browser zoom outside the video stage.
     */
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/*
 * Critical cross-browser rule: the feed's native <video> cannot become a
 * competing drag surface. The stage receives the hit; the event still bubbles
 * naturally to Swiper. /watch/ videos are unaffected and retain native controls.
 */
.fapswipe-native-stage[data-fapswipe-feed-interaction="1"] .fapswipe-native-video {
    pointer-events: none;
}

.fapswipe-native-stage[data-fapswipe-zoomed="1"] {
    cursor: grab;
}

.fapswipe-native-stage[data-fapswipe-zoomed="1"][data-fapswipe-gesture="pan"] {
    cursor: grabbing;
}

/* Promote only actively zoomed media to a compositor transform layer. */
.fapswipe-native-stage[data-fapswipe-zoomed="1"] .fapswipe-native-video {
    will-change: transform;
}

.fapswipe-native-stage[data-fapswipe-feed-interaction="1"]:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 4px;
}

/*
 * Double-tap zoom/reset is the only programmatic zoom animation. Pinch and pan
 * stay direct so the media follows the fingers without easing lag. Keeping the
 * transition marker on the stage also means future controls can cancel/replace
 * this behavior without inspecting inline styles.
 */
.fapswipe-native-stage[data-fapswipe-zoom-transition="1"] .fapswipe-native-video {
    transition: transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
    .fapswipe-native-stage[data-fapswipe-zoom-transition="1"] .fapswipe-native-video {
        transition-duration: 1ms;
    }
}


/*
 * FEED PLAYER SKINS
 * -----------------
 * Playback and gestures are shared. A skin only changes player chrome.
 *
 * - swipe: reference-inspired default for vertical feeds.
 * - bare: the smallest useful playback UI.
 * - full: conventional custom controls.
 *
 * Feed title/tags/social actions intentionally live outside this stylesheet.
 */

.fapswipe-native-controls,
.fapswipe-native-controls *,
.fapswipe-native-center-state,
.fapswipe-native-center-state * {
    box-sizing: border-box;
}

.fapswipe-native-controls {
    color: #fff;
    line-height: 1;
}

.fapswipe-native-control {
    appearance: none;
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    margin: 0;
    padding: 8px;
    border: 0;
    border-radius: 999px;
    background: rgb(0 0 0 / 0.42);
    color: #fff;
    cursor: pointer;
    touch-action: manipulation;
    transition:
        opacity 140ms ease,
        background-color 140ms ease,
        transform 140ms ease;
}

.fapswipe-native-control:hover,
.fapswipe-native-control:focus-visible {
    background: rgb(0 0 0 / 0.62);
}

.fapswipe-native-control:active {
    transform: scale(0.94);
}

.fapswipe-native-control:focus-visible,
.fapswipe-native-progress:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.fapswipe-native-icon,
.fapswipe-native-control > svg,
.fapswipe-native-center-icon > svg {
    display: block;
    width: 100%;
    height: 100%;
    fill: currentColor;
}

.fapswipe-native-icon-pause,
.fapswipe-native-icon-sound {
    display: none;
}

.fapswipe-native-stage[data-fapswipe-playback-state="playing"] .fapswipe-native-icon-play {
    display: none;
}

.fapswipe-native-stage[data-fapswipe-playback-state="playing"] .fapswipe-native-icon-pause {
    display: block;
}

.fapswipe-native-stage[data-fapswipe-muted="0"] .fapswipe-native-icon-muted {
    display: none;
}

.fapswipe-native-stage[data-fapswipe-muted="0"] .fapswipe-native-icon-sound {
    display: block;
}

.fapswipe-native-time {
    min-width: 3ch;
    color: #fff;
    font: 500 12px/1.2 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgb(0 0 0 / 0.8);
}

/*
 * Progress is intentionally plain/monochrome. JS updates only the CSS percentage
 * variable; seeking remains the same native range input used in 0.9.x.
 */
.fapswipe-native-progress {
    --fapswipe-native-progress-value: 0%;

    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    min-width: 70px;
    height: 28px;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: #fff;
    cursor: pointer;
    touch-action: none;
}

.fapswipe-native-progress::-webkit-slider-runnable-track {
    height: 3px;
    border: 0;
    border-radius: 999px;
    background:
        linear-gradient(
            to right,
            currentColor 0,
            currentColor var(--fapswipe-native-progress-value),
            rgb(255 255 255 / 0.35) var(--fapswipe-native-progress-value),
            rgb(255 255 255 / 0.35) 100%
        );
}

.fapswipe-native-progress::-moz-range-track {
    height: 3px;
    border: 0;
    border-radius: 999px;
    background: rgb(255 255 255 / 0.35);
}

.fapswipe-native-progress::-moz-range-progress {
    height: 3px;
    border: 0;
    border-radius: 999px;
    background: currentColor;
}

.fapswipe-native-progress::-webkit-slider-thumb {
    appearance: none;
    width: 12px;
    height: 12px;
    margin-top: -4.5px;
    border: 0;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 1px 4px rgb(0 0 0 / 0.45);
    transition: transform 120ms ease, opacity 120ms ease;
}

.fapswipe-native-progress::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border: 0;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 1px 4px rgb(0 0 0 / 0.45);
    transition: transform 120ms ease, opacity 120ms ease;
}

.fapswipe-native-progress:disabled {
    cursor: default;
    opacity: 0.45;
}

/* Center paused-state cue used by the swipe and bare skins. */
.fapswipe-native-center-state {
    position: absolute;
    z-index: 44;
    top: 50%;
    left: 50%;
    display: grid;
    place-items: center;
    width: 68px;
    height: 68px;
    padding: 18px;
    border-radius: 999px;
    background: rgb(0 0 0 / 0.38);
    color: #fff;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.88);
    transition: opacity 150ms ease, transform 150ms ease;
}

.fapswipe-native-center-icon {
    display: block;
    width: 100%;
    height: 100%;
}

:is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage[data-fapswipe-playback-state="paused"] .fapswipe-native-center-state,
html[data-fapswipe-native-skin="bare"] .fapswipe-native-stage[data-fapswipe-playback-state="paused"] .fapswipe-native-center-state {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* -------------------------------------------------------------------------
 * SWIPE SKIN — reference-inspired default
 * ---------------------------------------------------------------------- */

:is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage .fapswipe-native-controls {
    position: absolute;
    z-index: 45;
    inset: 0;
    opacity: 1;
    visibility: visible;
    pointer-events: none;
}

:is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage .fapswipe-native-play,
:is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage .fapswipe-native-time {
    display: none;
}

:is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage .fapswipe-native-mute,
:is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage .fapswipe-native-fullscreen {
    position: absolute;
    right: max(12px, env(safe-area-inset-right, 0px));
    opacity: 0;
    pointer-events: none;
    transform: translateX(4px);
}

:is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage .fapswipe-native-mute {
    top: max(12px, env(safe-area-inset-top, 0px));
}

:is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage .fapswipe-native-fullscreen {
    top: calc(max(12px, env(safe-area-inset-top, 0px)) + 48px);
}

:is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage[data-fapswipe-controls-visible="1"] .fapswipe-native-mute,
:is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage[data-fapswipe-controls-visible="1"] .fapswipe-native-fullscreen {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
}

:is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage .fapswipe-native-progress {
    position: absolute;
    right: 0;
    bottom: max(0px, env(safe-area-inset-bottom, 0px));
    left: 0;
    z-index: 2;
    height: 22px;
    min-width: 0;
    pointer-events: none;
}

:is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage[data-fapswipe-controls-visible="1"] .fapswipe-native-progress {
    pointer-events: auto;
}

:is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage:not([data-fapswipe-controls-visible="1"])
    .fapswipe-native-progress::-webkit-slider-thumb {
    opacity: 0;
    transform: scale(0.65);
}

:is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage:not([data-fapswipe-controls-visible="1"])
    .fapswipe-native-progress::-moz-range-thumb {
    opacity: 0;
    transform: scale(0.65);
}

/* -------------------------------------------------------------------------
 * BARE BONES — progress + audio, stage tap handles play/pause
 * ---------------------------------------------------------------------- */

html[data-fapswipe-native-skin="bare"] .fapswipe-native-stage .fapswipe-native-controls {
    position: absolute;
    z-index: 45;
    inset: 0;
    opacity: 1;
    visibility: visible;
    pointer-events: none;
}

html[data-fapswipe-native-skin="bare"] .fapswipe-native-stage .fapswipe-native-play,
html[data-fapswipe-native-skin="bare"] .fapswipe-native-stage .fapswipe-native-time,
html[data-fapswipe-native-skin="bare"] .fapswipe-native-stage .fapswipe-native-fullscreen {
    display: none;
}

html[data-fapswipe-native-skin="bare"] .fapswipe-native-stage .fapswipe-native-mute {
    position: absolute;
    top: max(12px, env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    width: 36px;
    height: 36px;
    padding: 8px;
    opacity: 0;
    pointer-events: none;
}

html[data-fapswipe-native-skin="bare"] .fapswipe-native-stage[data-fapswipe-controls-visible="1"] .fapswipe-native-mute {
    opacity: 1;
    pointer-events: auto;
}

html[data-fapswipe-native-skin="bare"] .fapswipe-native-stage .fapswipe-native-progress {
    position: absolute;
    right: 0;
    bottom: max(0px, env(safe-area-inset-bottom, 0px));
    left: 0;
    height: 20px;
    min-width: 0;
    pointer-events: none;
}

html[data-fapswipe-native-skin="bare"] .fapswipe-native-stage[data-fapswipe-controls-visible="1"] .fapswipe-native-progress {
    pointer-events: auto;
}

html[data-fapswipe-native-skin="bare"] .fapswipe-native-stage:not([data-fapswipe-controls-visible="1"])
    .fapswipe-native-progress::-webkit-slider-thumb {
    opacity: 0;
}

html[data-fapswipe-native-skin="bare"] .fapswipe-native-stage:not([data-fapswipe-controls-visible="1"])
    .fapswipe-native-progress::-moz-range-thumb {
    opacity: 0;
}

/* -------------------------------------------------------------------------
 * FULL CONTROLS — conventional dock
 * ---------------------------------------------------------------------- */

html[data-fapswipe-native-skin="full"] .fapswipe-native-stage .fapswipe-native-center-state {
    display: none;
}

html[data-fapswipe-native-skin="full"] .fapswipe-native-stage .fapswipe-native-controls {
    position: absolute;
    z-index: 45;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom, 0px));
    left: 10px;
    display: grid;
    grid-template-columns: 40px 40px auto minmax(70px, 1fr) auto 40px;
    gap: 7px;
    align-items: center;
    min-height: 48px;
    padding: 6px 8px;
    border: 1px solid rgb(255 255 255 / 0.12);
    border-radius: 12px;
    background: rgb(0 0 0 / 0.62);
    box-shadow: 0 4px 18px rgb(0 0 0 / 0.22);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(5px);
    transition:
        opacity 140ms ease,
        transform 140ms ease,
        visibility 140ms linear;
}

html[data-fapswipe-native-skin="full"] .fapswipe-native-stage[data-fapswipe-controls-visible="1"] .fapswipe-native-controls {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

/* Standard Fullscreen keeps our own controls/gestures and lets Fit own geometry. */
.fapswipe-native-stage:fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    background: #000;
}

.fapswipe-native-stage:fullscreen .fapswipe-native-video {
    max-width: 100% !important;
    max-height: 100% !important;
}

@media (max-width: 560px) {
    .fapswipe-native-control {
        width: 38px;
        height: 38px;
        padding: 8px;
    }

    .fapswipe-native-center-state {
        width: 62px;
        height: 62px;
        padding: 17px;
    }

    html[data-fapswipe-native-skin="full"] .fapswipe-native-stage .fapswipe-native-controls {
        right: 6px;
        bottom: max(6px, env(safe-area-inset-bottom, 0px));
        left: 6px;
        grid-template-columns: 36px 36px auto minmax(52px, 1fr) auto 36px;
        gap: 4px;
        min-height: 44px;
        padding: 5px 6px;
    }

    html[data-fapswipe-native-skin="full"] .fapswipe-native-stage .fapswipe-native-control {
        width: 36px;
        height: 36px;
        padding: 7px;
    }

    .fapswipe-native-time {
        font-size: 11px;
    }

    :is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage .fapswipe-native-mute,
    :is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage .fapswipe-native-fullscreen {
        right: max(10px, env(safe-area-inset-right, 0px));
    }

    :is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage .fapswipe-native-mute,
    html[data-fapswipe-native-skin="bare"] .fapswipe-native-stage .fapswipe-native-mute {
        top: max(10px, env(safe-area-inset-top, 0px));
    }

    :is(html[data-fapswipe-native-skin="swipe"], html:not([data-fapswipe-native-skin])) .fapswipe-native-stage .fapswipe-native-fullscreen {
        top: calc(max(10px, env(safe-area-inset-top, 0px)) + 44px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .fapswipe-native-control,
    .fapswipe-native-center-state,
    html[data-fapswipe-native-skin="full"] .fapswipe-native-stage .fapswipe-native-controls {
        transition: none;
    }
}
