/*
 * tvt-popup: what Tailwind classes cannot say for the pop-ups (public/js/tvt-popup.js, demo /templates/demo/tvt-popup):
 * the bottom sheet of phones, the flip of a card, the countdown's ticks, the outlined text, the sticker, the ribbon,
 * the boarding pass (barcode, the stub that tears off), the scratch card, the postcard's postmark and the ringing phone.
 */

/* bottom sheet: below md the panel slides up from the bottom instead of growing (the modal toggles scale-95 / opacity-0) */
@media (max-width: 767.98px) {
    .tvt-popup [data-tvt-modal-panel] {
        scale: none;
        transition-property: translate, opacity;
        transition-duration: 300ms;
    }

    .tvt-popup [data-tvt-modal-panel].opacity-0 {
        translate: 0 100%;
        opacity: 1;
    }
}

/* flip card: both faces in one grid cell (the height of the taller one), the back one turned away */
.tvt-popup-flip {
    display: grid;
    perspective: 1800px;
}

.tvt-popup-flip > [data-tvt-popup-face] {
    grid-area: 1 / 1;
    backface-visibility: hidden;
    transition: rotate 700ms cubic-bezier(0.3, 1.3, 0.5, 1);
}

.tvt-popup-flip > [data-tvt-popup-face='back'] {
    rotate: y 180deg;
}

.tvt-popup-flip.is-flipped > [data-tvt-popup-face='front'] {
    rotate: y -180deg;
}

.tvt-popup-flip.is-flipped > [data-tvt-popup-face='back'] {
    rotate: y 0deg;
}

/* the ticket of a code: two notches cut in its sides, in the colour behind it (--tvt-popup-notch) */
.tvt-popup-ticket {
    position: relative;
}

.tvt-popup-ticket::before,
.tvt-popup-ticket::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 1rem;
    height: 1rem;
    margin-top: -0.5rem;
    border-radius: 9999px;
    background: var(--tvt-popup-notch, var(--color-tvt-brand));
}

.tvt-popup-ticket::before {
    left: -0.5rem;
}

.tvt-popup-ticket::after {
    right: -0.5rem;
}

/* outlined text: the letters drawn, not filled */
.tvt-popup-outline {
    color: transparent;
    -webkit-text-stroke: 2px currentColor;
    -webkit-text-fill-color: transparent;
}

/* the diagonal edge of a side photo */
.tvt-popup-diagonal {
    clip-path: polygon(14% 0, 100% 0, 100% 100%, 0 100%);
}

/* a sticker that sways a little */
.tvt-popup-sticker {
    animation: tvt-popup-sway 4s ease-in-out infinite;
}

@keyframes tvt-popup-sway {
    0%, 100% { rotate: 10deg; }
    50% { rotate: 16deg; }
}

/* a number of the countdown that changed drops in */
.tvt-popup-tick {
    animation: tvt-popup-tick 400ms cubic-bezier(0.2, 1.4, 0.5, 1);
}

@keyframes tvt-popup-tick {
    from { translate: 0 -40%; opacity: 0.2; }
    to { translate: 0 0; opacity: 1; }
}

/* a ribbon of words that runs across (two copies of the text, the second one taking the place of the first) */
.tvt-popup-ribbon {
    display: flex;
    width: max-content;
    animation: tvt-popup-ribbon 24s linear infinite;
}

@keyframes tvt-popup-ribbon {
    to { translate: -50% 0; }
}

/* boarding pass: the stub tears off once its code is copied */
.tvt-popup-stub {
    transition: rotate 500ms cubic-bezier(0.3, 1.4, 0.5, 1), translate 500ms cubic-bezier(0.3, 1.4, 0.5, 1);
    transform-origin: top left;
}

.tvt-popup-stub.is-torn {
    rotate: 4deg;
    translate: 0.5rem 0.75rem;
}

@media (max-width: 767.98px) {
    .tvt-popup-stub.is-torn {
        rotate: -3deg;
        translate: 0 0.75rem;
    }
}

/* boarding pass: the two notches of the perforation cut out of both parts (half a hole each), so what is behind the
   pass shows through them; phones: the stub below (notches left and right), from md on the right (top and bottom) */
.tvt-popup-pass-main,
.tvt-popup-stub {
    -webkit-mask: var(--tvt-popup-masks);
    mask: var(--tvt-popup-masks);
}

.tvt-popup-pass-main {
    --tvt-popup-masks:
        radial-gradient(circle at 0 100%, #0000 10px, #000 10.5px) left / 51% 100% no-repeat,
        radial-gradient(circle at 100% 100%, #0000 10px, #000 10.5px) right / 51% 100% no-repeat;
}

.tvt-popup-stub {
    --tvt-popup-masks:
        radial-gradient(circle at 0 0, #0000 10px, #000 10.5px) left / 51% 100% no-repeat,
        radial-gradient(circle at 100% 0, #0000 10px, #000 10.5px) right / 51% 100% no-repeat;
}

@media (min-width: 768px) {
    .tvt-popup-pass-main {
        --tvt-popup-masks:
            radial-gradient(circle at 100% 0, #0000 10px, #000 10.5px) top / 100% 51% no-repeat,
            radial-gradient(circle at 100% 100%, #0000 10px, #000 10.5px) bottom / 100% 51% no-repeat;
    }

    .tvt-popup-stub {
        --tvt-popup-masks:
            radial-gradient(circle at 0 0, #0000 10px, #000 10.5px) top / 100% 51% no-repeat,
            radial-gradient(circle at 0 100%, #0000 10px, #000 10.5px) bottom / 100% 51% no-repeat;
    }
}

/* a barcode drawn in the text colour */
.tvt-popup-barcode {
    background: repeating-linear-gradient(90deg, currentColor 0 2px, transparent 2px 4px, currentColor 4px 5px, transparent 5px 8px, currentColor 8px 11px, transparent 11px 12px, currentColor 12px 13px, transparent 13px 16px);
}

/* scratch card: the silver fades out once the prize is revealed; no scrolling while scratching */
.tvt-popup-scratch canvas {
    touch-action: none;
    cursor: grab;
    transition: opacity 600ms;
}

.tvt-popup-scratch.is-revealed canvas {
    opacity: 0;
    pointer-events: none;
}

.tvt-popup-scratch [data-tvt-popup-scratch-prize] {
    transition: scale 600ms cubic-bezier(0.3, 1.6, 0.5, 1);
}

.tvt-popup-scratch.is-revealed [data-tvt-popup-scratch-prize] {
    scale: 1.06;
}

/* postcard: the "posted" stamp falls on the card once the form is sent (is-done, tvt-popup.js) */
.tvt-popup-posted {
    opacity: 0;
    scale: 2.4;
    rotate: -14deg;
}

.tvt-popup-posted.is-done {
    animation: tvt-popup-stamp 500ms cubic-bezier(0.5, 0, 0.6, 1.4) forwards;
}

@keyframes tvt-popup-stamp {
    to { opacity: 0.9; scale: 1; }
}

/* a phone that rings */
.tvt-popup-ring {
    animation: tvt-popup-ring 1.6s ease-in-out infinite;
}

@keyframes tvt-popup-ring {
    0%, 40%, 100% { rotate: 0deg; }
    5%, 15%, 25% { rotate: -14deg; }
    10%, 20%, 30% { rotate: 14deg; }
}

@media (prefers-reduced-motion: reduce) {
    .tvt-popup,
    .tvt-popup [data-tvt-modal-panel],
    .tvt-popup-flip > [data-tvt-popup-face],
    .tvt-popup-stub,
    .tvt-popup-scratch canvas,
    .tvt-popup-scratch [data-tvt-popup-scratch-prize] {
        transition: none;
    }

    .tvt-popup-sticker,
    .tvt-popup-tick,
    .tvt-popup-ribbon,
    .tvt-popup-ring {
        animation: none;
    }

    .tvt-popup-posted.is-done {
        animation: none;
        opacity: 0.9;
        scale: 1;
    }
}
