/* =========================================================
   Mufti Taqi Usmani sahb's video about Darul Ifta Al-Ikhlas
   Markup is built by js/yt-float.js from the old sidebar card.

   Desktop (>= 992px), every page:
     .ytf-side  - new sidebar card in place of the old one,
                  blinking play button, click -> centred player
   Mobile (<= 991px), home page only:
     .ytf       - floating card at the bottom; hides on scroll
                  down, comes back on scroll up; tap -> bottom sheet
   Both:
     .ytf-sheet - the player

   Look: one solid deep navy (from the site blue #0268B2), white
   text, YouTube-red play button. No gradients on the surfaces.
========================================================= */

/* ---------- Shared colours + motion ---------- */
.ytf,
.ytf-side,
.ytf-sheet {
    --ytf-bg: #0b2a47;            /* deep navy */
    --ytf-bg-raised: #123657;     /* close button, hover */
    --ytf-line: rgba(255, 255, 255, .1);
    --ytf-text: #ffffff;
    --ytf-text-2: rgba(255, 255, 255, .78);
    --ytf-accent: #7cc0f2;        /* light site blue */
    --ytf-red: #ff0033;           /* YouTube */
    --ytf-in: cubic-bezier(.16, 1, .3, 1);
    --ytf-out: cubic-bezier(.7, 0, .84, 0);
}

/* ---------- Shared text (card, sidebar card, player) ---------- */
/* Title: English and Urdu share one spot and take turns every 3s
   (js/yt-float.js startTextSwap). Stacked in one grid cell, so the box
   is as tall as the taller line and never jumps. */
.ytf__rot {
    display: grid;
    overflow: hidden;
}
.ytf__line {
    grid-area: 1 / 1;
    align-self: center;
    margin: 0;
    text-align: center !important; /* site .UrduText is right-aligned */
    color: var(--ytf-text);
    /* waiting just below, invisible */
    opacity: 0;
    transform: translate3d(0, 10px, 0);
    transition: none;
    will-change: transform, opacity;
}
/* Sequence (no overlap):
   0 - .5s     old line drifts up 10px and fades out
   .5 - .65s   short pause, nothing shown
   .65 - 1.5s  new line rises 10px into place and fades in */
.ytf__line.is-out {
    opacity: 0;
    transform: translate3d(0, -10px, 0);
    transition: transform .5s cubic-bezier(.4, 0, 1, 1), opacity .45s ease-in;
}
.ytf__line.is-active {
    opacity: 1;
    transform: none;
    transition: transform .85s cubic-bezier(.22, 1, .36, 1) .65s, opacity .7s ease-out .65s;
}
.ytf__en {
    font-size: 12px;
    font-weight: 500;
    line-height: 1.45;
    letter-spacing: .01em;
}
.ytf__urdu {
    display: block;
    font-size: 17px;
    line-height: 1.75;
    direction: rtl;
}

/* Close button (floating card + player) */
.ytf__close {
    flex: none;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: rgba(255, 255, 255, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color .2s ease, color .2s ease;
    -webkit-tap-highlight-color: transparent;
}
.ytf__close svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    fill: none;
}
.ytf__close:hover,
.ytf__close:active { background: var(--ytf-bg-raised); color: #fff; }
.ytf__close:focus-visible { outline: 2px solid var(--ytf-accent); outline-offset: 2px; }


/* =========================================================
   MOBILE: floating card (home page)
========================================================= */
.ytf { display: none; }

@media (max-width: 991px) {

    /* Old sidebar video: replaced by the floating card (home page only,
       js adds .ytf-source there) */
    .ytf-source { display: none !important; }

    .ytf {
        display: flex;
        align-items: center;
        gap: 4px;
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        z-index: 1030; /* under the WhatsApp drawer (1040) */
        max-width: 440px;
        margin: 0 auto;
        padding: 8px 6px 8px 8px;
        box-sizing: border-box;
        border-radius: 16px;
        background: var(--ytf-bg);
        box-shadow:
            0 0 0 1px var(--ytf-line) inset,
            0 18px 40px -12px rgba(5, 22, 40, .55),
            0 3px 8px rgba(5, 22, 40, .18);
        color: var(--ytf-text);
        /* hidden state */
        transform: translate3d(0, calc(100% + 24px), 0);
        opacity: 0;
        pointer-events: none;
        will-change: transform, opacity;
        transition: transform .38s var(--ytf-out), opacity .25s ease .1s;
    }
    .ytf.is-shown {
        transform: translate3d(0, 0, 0);
        opacity: 1;
        pointer-events: auto;
        transition: transform .7s var(--ytf-in), opacity .35s ease;
    }

    /* Thumbnail and text settle in just after the card */
    .ytf__thumb,
    .ytf__text {
        opacity: 0;
        transition: opacity .15s ease, transform .15s ease;
    }
    .ytf__thumb { transform: scale(.92); }
    .ytf__text  { transform: translate3d(0, 5px, 0); }
    .ytf.is-shown .ytf__thumb,
    .ytf.is-shown .ytf__text {
        opacity: 1;
        transform: none;
    }
    .ytf.is-shown .ytf__thumb { transition: opacity .45s ease .12s, transform .7s var(--ytf-in) .12s; }
    .ytf.is-shown .ytf__text  { transition: opacity .5s ease .22s, transform .7s var(--ytf-in) .22s; }

    /* Play button "pops" once when the card arrives */
    .ytf.is-shown .ytf__play { animation: ytfPop .6s var(--ytf-in) .45s both; }

    /* Whole card is the play button */
    .ytf__card {
        display: flex;
        align-items: center;
        gap: 12px;
        flex: 1 1 auto;
        min-width: 0;
        padding: 0;
        border: 0;
        background: none;
        color: inherit;
        text-align: left;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .ytf__card:focus-visible {
        outline: 2px solid var(--ytf-accent);
        outline-offset: 3px;
        border-radius: 10px;
    }

    /* Thumbnail 16:9 */
    .ytf__thumb {
        position: relative;
        flex: none;
        width: 104px;
        height: 58.5px;
        border-radius: 10px;
        overflow: hidden;
        background: var(--ytf-bg-raised);
    }
    .ytf__img {
        position: absolute;
        inset: 0;
        background: center / cover no-repeat;
        transition: transform .5s var(--ytf-in);
    }
    .ytf__card:active .ytf__img { transform: scale(1.05); }
    .ytf__thumb::after {
        content: "";
        position: absolute;
        inset: 0;
        border-radius: inherit;
        box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
    }

    /* YouTube-red play button */
    .ytf__play {
        position: absolute;
        left: 50%;
        top: 50%;
        z-index: 1;
        width: 34px;
        height: 24px;
        margin: -12px 0 0 -17px;
        border-radius: 7px;
        background: var(--ytf-red);
        box-shadow: 0 3px 10px rgba(0, 0, 0, .35);
        display: flex;
        align-items: center;
        justify-content: center;
        transition: transform .3s var(--ytf-in);
    }
    .ytf__play svg {
        width: 10px;
        height: 10px;
        margin-left: 1px;
        fill: #fff;
    }
    .ytf__card:active .ytf__play { transform: scale(.9); }

    .ytf__text {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        justify-content: center;
        min-width: 0;
    }

    .ytf > .ytf__close { align-self: center; }

    /* Keep the "scroll to top" button above the card while it shows */
    .scroll-to-top { transition: bottom .6s cubic-bezier(.16, 1, .3, 1); }
    body.ytf-on .scroll-to-top { bottom: calc(104px + env(safe-area-inset-bottom, 0px)) !important; }
}


/* =========================================================
   DESKTOP: sidebar card (every page)
========================================================= */
.ytf-side { display: none; }

@media (min-width: 992px) {

    /* Old sidebar video: replaced by .ytf-side (js adds .ytf-replaced) */
    .ytf-replaced { display: none !important; }

    .ytf-side {
        display: block;
        margin-top: 20px;
        overflow: hidden;
        border-radius: 16px;
        background: var(--ytf-bg);
        box-shadow:
            0 0 0 1px rgba(11, 42, 71, .08),
            0 14px 32px -14px rgba(5, 22, 40, .45);
        color: var(--ytf-text);
        text-align: left;
        /* fades up when it scrolls into view (.is-in) */
        opacity: 0;
        transform: translate3d(0, 18px, 0);
        transition: opacity .6s ease, transform .8s var(--ytf-in), box-shadow .3s ease;
    }
    .ytf-side.is-in {
        opacity: 1;
        transform: none;
    }
    .ytf-side:hover {
        box-shadow:
            0 0 0 1px rgba(11, 42, 71, .1),
            0 20px 40px -14px rgba(5, 22, 40, .55);
    }

    /* Video still (16:9) - the whole image is the play button */
    .ytf-side__media {
        position: relative;
        display: block;
        width: 100%;
        padding: 56.25% 0 0;
        border: 0;
        background: var(--ytf-bg-raised);
        overflow: hidden;
        cursor: pointer;
    }
    .ytf-side__media:focus-visible {
        outline: 3px solid var(--ytf-accent);
        outline-offset: -3px;
    }
    .ytf-side__img {
        position: absolute;
        inset: 0;
        background: center / cover no-repeat;
        transition: transform .9s var(--ytf-in);
    }
    .ytf-side__media:hover .ytf-side__img { transform: scale(1.05); }
    .ytf-side__media::after { /* soft shade at the bottom so the chip reads */
        content: "";
        position: absolute;
        inset: 0;
        background: linear-gradient(180deg, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, .45) 100%);
        pointer-events: none;
    }

    /* Blinking YouTube-red "Watch now" button, bottom-left of the still.
       (Not centred: the thumbnail is a graphic with its own text there.) */
    .ytf-side__chip {
        position: absolute;
        left: 12px;
        bottom: 12px;
        z-index: 1;
        display: inline-flex;
        align-items: center;
        gap: 7px;
        padding: 8px 14px 8px 12px;
        border-radius: 999px;
        background: var(--ytf-red);
        color: #fff;
        font-size: 13px;
        font-weight: 700;
        line-height: 1;
        box-shadow: 0 0 0 0 rgba(255, 0, 51, .55), 0 6px 16px rgba(0, 0, 0, .3);
        animation: ytfBlink 1.8s ease-out infinite;
        transition: transform .3s var(--ytf-in);
    }
    .ytf-side__chip svg {
        width: 10px;
        height: 10px;
        fill: currentColor;
    }
    .ytf-side__media:hover .ytf-side__chip {
        animation-play-state: paused;
        transform: scale(1.06);
    }

    .ytf-side__body {
        padding: 12px 18px 14px;
    }
    .ytf-side__body .ytf__urdu { font-size: 19px; }
    .ytf-side__body .ytf__en { font-size: 13px; }
}


/* =========================================================
   PLAYER: bottom sheet (mobile) / centred window (desktop)
========================================================= */
.ytf-sheet {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    position: fixed;
    inset: 0;
    z-index: 1060;
    visibility: hidden;
    transition: visibility 0s .4s;
}
.ytf-sheet.is-open {
    visibility: visible;
    transition: none;
}
.ytf-sheet__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(4, 16, 29, .66);
    opacity: 0;
    transition: opacity .35s ease;
}
.ytf-sheet.is-open .ytf-sheet__backdrop { opacity: 1; }

.ytf-sheet__panel {
    position: relative;
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: 8px 16px calc(18px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
    border-radius: 22px 22px 0 0;
    background: var(--ytf-bg);
    box-shadow: 0 -1px 0 var(--ytf-line), 0 -14px 36px rgba(4, 16, 29, .35);
    color: var(--ytf-text);
    transform: translate3d(0, 100%, 0);
    transition: transform .38s var(--ytf-out);
}
.ytf-sheet.is-open .ytf-sheet__panel {
    transform: none;
    transition: transform .6s var(--ytf-in);
}
.ytf-sheet__grip {
    width: 36px;
    height: 4px;
    margin: 0 auto 14px;
    border-radius: 4px;
    background: rgba(255, 255, 255, .22);
}
.ytf-sheet__head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}
/* left padding = close button width, so the Urdu line sits truly centred */
.ytf-sheet__titles { flex: 1 1 auto; min-width: 0; padding-left: 44px; }
.ytf-sheet__head .ytf__urdu { font-size: 20px; }
.ytf-sheet__head .ytf__en { font-size: 14px; }
.ytf-sheet__head .ytf__close { width: 32px; height: 32px; background: var(--ytf-bg-raised); color: #fff; }

.ytf-sheet__video {
    position: relative;
    padding-top: 56.25%;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    box-shadow: 0 0 0 1px var(--ytf-line);
}
.ytf-sheet__video iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Content fades in after the panel */
.ytf-sheet__head,
.ytf-sheet__video,
.ytf-sheet__yt {
    opacity: 0;
    transition: opacity .15s ease;
}
.ytf-sheet.is-open .ytf-sheet__head,
.ytf-sheet.is-open .ytf-sheet__video,
.ytf-sheet.is-open .ytf-sheet__yt {
    opacity: 1;
    transition: opacity .45s ease .15s;
}

.ytf-sheet__yt {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 14px;
    min-height: 46px;
    border: 0 !important;
    border-radius: 12px;
    background: #fff;
    color: #0b2a47 !important;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none !important;
    transition: transform .2s ease, background-color .2s ease;
}
.ytf-sheet__yt:hover { background: #eef4fa; }
.ytf-sheet__yt:active { transform: scale(.98); }
.ytf-sheet__yt svg { width: 20px; height: 14px; }

body.ytf-lock { overflow: hidden; }

/* Desktop: centred window instead of a bottom sheet */
@media (min-width: 992px) {
    .ytf-sheet {
        justify-content: center;
        align-items: center;
    }
    .ytf-sheet__panel {
        width: calc(100% - 64px);
        max-width: 820px;
        padding: 20px 22px 22px;
        border-radius: 20px;
        box-shadow: 0 0 0 1px var(--ytf-line), 0 30px 80px rgba(4, 16, 29, .5);
        opacity: 0;
        transform: translate3d(0, 24px, 0) scale(.97);
        transition: transform .3s var(--ytf-out), opacity .25s ease;
    }
    .ytf-sheet.is-open .ytf-sheet__panel {
        opacity: 1;
        transform: none;
        transition: transform .6s var(--ytf-in), opacity .35s ease;
    }
    .ytf-sheet__grip { display: none; }
    .ytf-sheet__yt {
        width: max-content;
        margin: 16px auto 0;
        padding: 0 22px;
    }
}


/* ---------- Animations ---------- */
@keyframes ytfPop {
    0%   { transform: scale(.6); }
    60%  { transform: scale(1.1); }
    100% { transform: scale(1); }
}
@keyframes ytfBlink {
    0%   { box-shadow: 0 0 0 0 rgba(255, 0, 51, .55), 0 6px 16px rgba(0, 0, 0, .3); transform: scale(1); }
    15%  { transform: scale(1.06); }
    30%  { transform: scale(1); }
    70%  { box-shadow: 0 0 0 14px rgba(255, 0, 51, 0), 0 6px 16px rgba(0, 0, 0, .3); }
    100% { box-shadow: 0 0 0 0 rgba(255, 0, 51, 0), 0 6px 16px rgba(0, 0, 0, .3); transform: scale(1); }
}

@media (max-width: 360px) {
    .ytf__thumb { width: 90px; height: 50.6px; }
    .ytf .ytf__urdu { font-size: 15.5px; }
    .ytf .ytf__en { font-size: 11.5px; }
}

@media (prefers-reduced-motion: reduce) {
    .ytf, .ytf.is-shown { transform: none; transition: opacity .25s ease; }
    .ytf__thumb, .ytf__text { transform: none !important; }
    .ytf__line, .ytf__line.is-active, .ytf__line.is-out { transform: none !important; }
    .ytf.is-shown .ytf__play, .ytf-side__chip { animation: none; }
    .ytf-side, .ytf-side.is-in { transform: none; }
    .ytf-sheet__panel, .ytf-sheet.is-open .ytf-sheet__panel { transition: none; }
}

@media print {
    .ytf, .ytf-side, .ytf-sheet { display: none !important; }
}
