:root {
    --highlight-bg: var(--ardoise-40);
    --highlight-progress: var(--ardoise-40);
    --highlight-head: var(--ardoise-40);
    --highlight-color: var(--ardoise-90);
    --highlight-duration: 20s;
    --highlight-transition: 300ms;
}

.home {
    position: relative;

    h1 {
        z-index: 1;
    }

    .presentation {
        font-size: 1.5rem;
        font-weight: 100;
        line-height: 1.25em;
        /*margin-block: 5rem;*/
    }

    .highlighted-series {
        align-items: center;
        background-color: var(--highlight-bg);
        box-shadow: 0 0 4rem 6rem var(--highlight-bg);
        color: var(--highlight-color);
        display: flex;
        gap: 1rem;
        height: 36vw;
        justify-content: center;
        margin-block: 8rem;
        margin-inline: auto;
        position: relative;
        transition: background-color var(--highlight-transition), box-shadow var(--highlight-transition);
        width: 90vw;

        .poster {
            aspect-ratio: 2 / 3;
            flex-shrink: 0;
            height: 115%;
            opacity: 0;
            rotate: 3deg;
            transition: opacity var(--highlight-transition);


            &.show {
                opacity: 1;
            }

            img {
                border: .75rem solid var(--orange-90);
                border-radius: .25rem;
                box-shadow: 0 0 2rem rgba(0, 0, 0, .25);
                height: 100%;
                object-fit: cover;
                width: 100%;
            }
        }

        .infos {
            display: flex;
            flex-direction: column;
            gap: 1rem;
            height: 24dvh;
            justify-content: center;

            .details {
                display: flex;
                flex-direction: column;
                gap: 1rem;
                justify-content: center;
                opacity: 0;
                transition: opacity var(--highlight-transition);

                &.show {
                    opacity: 1;
                }

                a {
                    color: var(--highlight-color);

                    .name {
                        font-size: 2rem;
                        font-weight: 100;
                        line-height: 1.25em;
                        padding-inline: 1rem;
                    }
                }

                .overview {
                    font-size: 1.1rem;
                    font-weight: 100;
                    line-height: 1.25em;
                    overflow-y: auto;
                    padding-inline: 1rem;
                }

                .providers {
                    flex-shrink: 0;
                    overflow-x: auto;

                    .wrapper {
                        align-items: center;
                        display: flex;
                        gap: 1rem;
                        justify-content: flex-start;
                        padding-inline: 1rem;

                        .provider {
                            align-items: center;
                            display: flex;
                            flex-shrink: 0;
                            gap: .5rem;
                            height: 4rem;

                            img {
                                border-radius: .25rem;
                                height: clamp(2rem, 5vw, 4rem);
                                object-fit: cover;
                                width: clamp(2rem, 5vw, 4rem);;
                            }

                            .name {
                                font-size: 1.1rem;
                                font-weight: 100;
                                line-height: 1.25em;
                                white-space: nowrap;
                            }
                        }
                    }
                }
            }

            .poster-list {
                display: flex;
                flex-wrap: wrap;
                justify-content: center;
                width: 100%;

                .item {
                    align-items: center;
                    display: flex;
                    flex-direction: column;
                    gap: .25rem;
                    height: 7vw;
                    max-width: 5vw;

                    &.counter {
                        height: 5vw;
                        margin-block-start: 1vw;
                        margin-inline-end: 1vw;
                        max-width: unset;
                        width: 5vw;

                        div {
                            align-items: center;
                            aspect-ratio: 1;
                            background-color: var(--orange-50);
                            border: .125rem solid var(--orange-90);
                            border-radius: 50%;
                            color: var(--orange-90);
                            display: flex;
                            font-size: 3vw;
                            height: 100%;
                            justify-content: center;
                            margin-inline-end: .25rem;
                            width: 100%;
                        }
                    }

                    .poster-item {
                        border: .125rem solid transparent;
                        border-radius: .375rem;
                        height: 6vw;
                        object-fit: cover;
                        width: 4vw;

                        &.active {
                            border-color: var(--orange-50);
                        }

                        img {
                            border-radius: .25rem;
                            height: calc(6vw - .25rem);
                            object-fit: cover;
                            width: calc(4vw - .25rem);
                        }
                    }

                    .count {
                        display: flex;
                        flex-wrap: wrap;
                        height: .75rem;
                        justify-content: center;
                        width: 100%;

                        > div {
                            background-color: var(--orange-50);
                            border-radius: 50%;
                            height: .25rem;
                            width: .25rem;
                        }
                    }
                }
            }
        }

        .loading {
            align-items: center;
            border-radius: 50%;
            height: 20vw;
            left: 50%;
            opacity: 0;
            position: absolute;
            top: 50%;
            translate: -50% -50%;
            transition: opacity var(--highlight-transition);
            width: 20vw;
            z-index: 1;

            &.show {
                animation: spin 1s linear infinite;
                opacity: 1;
            }

            .loading-item {
                background-color: var(--orange-50);
                border-radius: 50%;
                border-top: .5rem solid;
                height: 2rem;
                position: absolute;
                translate: -50% -50%;
                width: 2rem;

                &:first-child {
                    left: 25%;
                    top: 25%;
                }

                &:nth-child(2) {
                    left: 75%;
                    top: 25%;
                }

                &:nth-child(3) {
                    left: 25%;
                    top: 75%;
                }

                &:nth-child(4) {
                    left: 75%;
                    top: 75%;
                }
            }
        }

        .loading-v2 {
            inset: 0;
            position: absolute;

            .ball-container {
                height: 100%;
                position: relative;
                width: 100%;

                .ball {
                    background-color: var(--orange-50);
                    border-radius: 50%;
                    height: 2rem;
                    position: absolute;
                    width: 2rem;
                }
            }
        }
    }

    .highlight-progress {
        background-color: var(--highlight-progress);
        border-radius: 0 1rem 1rem 0;
        box-shadow: 0 0 3rem 1rem var(--highlight-bg);
        height: 3px;
        left: 0;
        position: absolute;
        top: 1.5rem;
        width: 0;

        &.show {
            transition: width var(--highlight-duration) linear;
            width: 100%;
        }

        .head {
            aspect-ratio: 1;
            background-color: var(--highlight-head);
            border-radius: 50%;
            box-shadow: 0 0 1rem 12px var(--highlight-head);
            height: 100%;
            position: absolute;
            right: 0;
            top: 0;

        }
    }

    .series-status {
        align-items: stretch;
        background-color: var(--orange-40);
        border-radius: 1rem;
        color: var(--orange-80);
        display: flex;
        font-size: 1.5rem;
        font-weight: 600;
        justify-content: center;
        margin-inline: auto;
        overflow: hidden;

        &.vertical {
            flex-direction: column;
        }

        .status-title {
            align-items: center;
            background-color: var(--green);
            display: flex;
            justify-content: center;
            min-height: 100%;
            padding-block: 1vw;
            padding-inline: 2vw;
            text-align: center;
            text-wrap: balance;
        }

        .status-items {
            align-items: center;
            display: flex;
            flex-grow: 1;
            flex-wrap: wrap;
            gap: 1rem;
            justify-content: center;
            padding: 2rem;

            &:not(:has(> .status-item)) {
                flex-direction: column;
            }

            .status-item {
                align-items: center;
                background-color: var(--orange-30);
                border-radius: 1rem;
                display: flex;
                flex-direction: column;
                gap: .5rem;
                justify-content: center;
                padding: 1rem;

                .name {
                    font-size: 1rem;
                    font-weight: 400;
                    line-height: 1.1em;
                    text-transform: uppercase;
                }

                .count {
                    font-size: 3rem;
                    font-weight: 800;
                    line-height: 1.1em;
                }

                .percent {
                    color: var(--orange-90);
                    font-size: 1rem;
                    font-weight: 400;
                    line-height: 1.1em;
                }
            }

            .status-item-line {
                align-items: center;
                display: flex;
                flex-grow: 1;
                flex-wrap: wrap;
                gap: 1rem;
                justify-content: center;
            }
        }
    }

    .provider-ranking {
        align-items: stretch;
        background-color: var(--orange-20);
        border-radius: 1rem;
        color: var(--orange-80);
        display: flex;
        flex-direction: column;
        font-size: 1.5rem;
        font-weight: 600;
        justify-content: center;
        margin-inline: auto;
        max-width: 100%;
        overflow: hidden;

        .ranking-title {
            align-items: center;
            background-color: var(--green-80);
            display: flex;
            gap: 1rem;
            justify-content: center;
            min-height: 100%;
            padding-block: 1vw;
            padding-inline: 2vw;
            text-align: center;
            text-wrap: balance;
        }

        .ranking-content {
            display: flex;

            .ranking-wrapper {
                display: flex;

                .ranking-items {
                    align-items: center;
                    display: flex;
                    flex-grow: 1;
                    flex-wrap: wrap;
                    gap: 1rem;
                    justify-content: center;
                    padding: 2rem;

                    &:not(:has(> .ranking-item)) {
                        flex-direction: column;
                    }

                    .ranking-item {
                        align-items: center;
                        background-color: var(--orange-30);
                        border-radius: 1rem;
                        display: flex;
                        gap: .5rem;
                        height: 4rem;
                        justify-content: center;
                        padding-inline: 1rem;

                        &:has(img) {
                            padding-inline-start: 0;
                        }

                        .logo {
                            aspect-ratio: 1;
                            height: 4rem;
                            width: 4rem;

                            img {
                                border-radius: 1rem 0 0 1rem;
                                height: 100%;
                                object-fit: cover;
                                width: 100%;
                            }
                        }

                        .index {
                            align-items: center;
                            aspect-ratio: 1;
                            background-color: var(--orange-80);
                            border-radius: 25rem;
                            color: var(--orange-20);
                            display: flex;
                            height: 2.75rem;
                            justify-content: center;
                        }

                        .name {
                            font-size: 1rem;
                            font-weight: 400;
                            line-height: 1.1em;
                            text-transform: uppercase;
                        }

                        .count {
                            font-size: 3rem;
                            font-weight: 800;
                            line-height: 1.1em;
                        }

                        .percent {
                            color: var(--orange-90);
                            font-size: 1rem;
                            font-weight: 400;
                            line-height: 1.1em;
                        }
                    }

                    .status-item-line {
                        align-items: center;
                        display: flex;
                        flex-grow: 1;
                        flex-wrap: wrap;
                        gap: 1rem;
                        justify-content: center;
                    }
                }
            }
        }

        &.bar-chart {

            .ranking-title {
                align-items: center;
                background-color: var(--green);
                display: flex;
                gap: 1rem;
                justify-content: center;
                min-height: 100%;
                padding-block: 1vw;
                padding-inline: 2vw;
                text-align: center;
                text-wrap: balance;
            }

            .ranking-gauge {
                align-items: center;
                background-color: var(--orange-20);
                border-radius: 1rem;
                display: flex;
                flex-direction: column;
                height: 3rem;
                justify-content: center;
                margin-inline: auto;
                width: min(40rem, 100% - 8rem);
            }

            .double-range-slider {
                height: 1rem;
                position: relative;
                text-align: center;
                width: 100%;

                input[type="range"] {
                    pointer-events: none;
                    position: absolute;
                    -webkit-appearance: none;
                    -webkit-tap-highlight-color: rgba(255, 255, 255, 0);
                    border: none;
                    border-radius: 14px;
                    background: transparent;
                    overflow: hidden;
                    left: 0;
                    top: 0;
                    width: 100%;
                    outline: none;
                    height: 1.5rem;
                    margin: 0;
                    padding: 0;
                }

                input[type="range"]::-webkit-slider-runnable-track {
                    background-color: var(--orange-40);
                    border-radius: 14px;
                    height: 1rem;
                    width: 100%;
                }

                label:last-of-type input[type="range"]::-webkit-slider-runnable-track {
                    background-color: var(--orange-30);
                }

                input[type="range"]::-webkit-slider-thumb {
                    -webkit-appearance: none;
                    background-color: var(--orange-60);
                    border-radius: 14px;
                    border: 4px solid var(--orange-90);
                    height: 1rem;
                    outline: 0;
                    pointer-events: all;
                    position: relative;
                    width: 1rem;
                    z-index: 1;
                }

                input[type="range"]::-moz-range-thumb {
                    -moz-appearance: none;
                    background-color: var(--orange-90);
                    border-radius: 14px;
                    border: 4px solid var(--orange-40);
                    height: 1rem;
                    pointer-events: all;
                    position: relative;
                    width: 1rem;
                    z-index: 10;
                }

                input[type=range]::-moz-range-track {
                    position: relative;
                    z-index: -1;
                    background-color: rgba(0, 0, 0, 1);
                    border: var(--orange-40);
                }

                input[type=range]:last-of-type::-moz-range-track {
                    -moz-appearance: none;
                    background: none transparent;
                    border: 0;
                }

                input[type=range]::-moz-focus-outer {
                    border: 0;
                }
            }

            .ranking-time-machine {
                display: flex;
                gap: 1rem;
                padding: 1rem;

                input[type="range"] {
                    --track-h: .75rem;
                    --thumb-size: 1.25rem;
                    --ratio: 1; /* 0 → 1, mis à jour dans ProviderRanking.js */
                    /* le centre du thumb ne parcourt que (100% - largeur du thumb) :
                       on décale l'arrêt du dégradé pour recaler le remplissage sur le thumb */
                    --fill: calc(var(--ratio) * (100% - var(--thumb-size)) + var(--thumb-size) / 2);

                    appearance: none;
                    background: transparent;
                    cursor: pointer;
                    margin: 0;
                    width: 100%;

                    /* WebKit / Blink : pas de pseudo-élément pour la partie gauche,
                       on la simule avec un dégradé à arrêt net piloté par --fill */
                    &::-webkit-slider-runnable-track {
                        background: linear-gradient(to right,
                        var(--green-50) var(--fill),
                        var(--green-20) var(--fill));
                        border-radius: calc(var(--track-h) / 2);
                        border: 1px solid var(--green-20);
                        height: var(--track-h);
                    }

                    &::-webkit-slider-thumb {
                        appearance: none;
                        background-color: var(--green-90);
                        border-radius: 50%;
                        border: 2px solid var(--green-50);
                        height: var(--thumb-size);
                        /* le thumb s'aligne en haut de la piste : on le recentre */
                        margin-block-start: calc((var(--track-h) - var(--thumb-size)) / 2);
                        width: var(--thumb-size);
                    }

                    /* Firefox : la partie gauche est un vrai pseudo-élément */
                    &::-moz-range-track {
                        background-color: var(--orange-10);
                        border-radius: calc(var(--track-h) / 2);
                        border: 1px solid var(--orange-10);
                        height: var(--track-h);
                    }

                    &::-moz-range-progress {
                        background-color: var(--orange-50);
                        border-radius: calc(var(--track-h) / 2);
                        height: var(--track-h);
                    }

                    &[id^=minRange]::-moz-range-progress {
                        background-color: var(--orange-20);
                        border-radius: calc(var(--track-h) / 2);
                        height: var(--track-h);
                    }

                    &::-moz-range-thumb {
                        background-color: var(--orange-90);
                        border-radius: 50%;
                        border: 2px solid var(--orange-50);
                        height: var(--thumb-size);
                        width: var(--thumb-size);
                    }

                    &:focus-visible {
                        outline: 2px solid var(--orange-90);
                        outline-offset: 4px;
                    }

                    /* pseudo-éléments standard : la partie gauche est gérée nativement */
                    @supports selector(::slider-fill) {
                        appearance: base;

                        &::slider-track {
                            background-color: var(--green-20);
                            border-radius: calc(var(--track-h) / 2);
                            height: var(--track-h);
                        }

                        &::slider-fill {
                            background-color: var(--orange-50);
                            border-radius: calc(var(--track-h) / 2);
                        }

                        &::slider-thumb {
                            background-color: var(--orange-90);
                            border-radius: 50%;
                            border: 2px solid var(--orange-50);
                            height: var(--thumb-size);
                            width: var(--thumb-size);
                        }
                    }
                }
            }

            .ranking-content {
                display: flex;
                padding-block: 1rem 2rem;
                padding-inline: 2rem;
                position: relative;
                width: 100%;

                .ranking-total {
                    align-items: center;
                    display: flex;
                    flex-direction: row;
                    gap: 1rem;
                    padding-inline: 1rem;
                    position: absolute;
                    top: 1rem;
                    right: 1rem;
                    width: fit-content;
                    z-index: 1;

                    .name, .percent {
                        font-size: 1rem;
                        font-weight: 400;
                        line-height: 1.1em;
                        text-transform: uppercase;
                    }

                    .count {
                        font-size: 3rem;
                        font-weight: 800;
                        line-height: 1.1em;
                    }
                }

                .ranking-wrapper {
                    display: flex;
                    overflow-x: auto;
                    padding-block: 3rem 0;
                    padding-inline: 0;
                    width: 100%;

                    .ranking-items {
                        align-items: flex-end;
                        display: flex;
                        flex-grow: 1;
                        flex-wrap: nowrap;
                        gap: 1rem;
                        justify-content: center;
                        padding: 0;

                        .ranking-item {
                            align-items: space-between;
                            background-color: var(--orange-30);
                            border-radius: 1rem;
                            display: flex;
                            flex-direction: column;
                            gap: .5rem;
                            height: 7rem;
                            justify-content: center;
                            min-height: 7rem;
                            padding-block: 1rem;
                            padding-inline: 0;
                            position: relative;
                            width: 4rem;

                            &:has(img) {
                                padding-block-start: 0;
                            }

                            .logo {
                                aspect-ratio: 1;
                                height: 4rem;
                                margin-block-end: auto;
                                width: 4rem;

                                img {
                                    border-radius: 1rem 1rem 0 0;
                                    height: 100%;
                                    object-fit: cover;
                                    width: 100%;
                                }
                            }

                            .index {
                                align-items: center;
                                aspect-ratio: 1;
                                background-color: var(--orange-80);
                                border-radius: 25rem;
                                color: var(--orange-20);
                                display: flex;
                                height: 2.75rem;
                                justify-content: center;
                                position: absolute;
                                top: -3rem;
                            }

                            .percent {
                                color: var(--orange-90);
                                font-size: 1rem;
                                font-weight: 400;
                                line-height: 1.1em;
                                margin-block-start: auto;
                            }
                        }

                        .status-item-line {
                            align-items: center;
                            display: flex;
                            flex-grow: 1;
                            flex-wrap: wrap;
                            gap: 1rem;
                            justify-content: center;
                        }
                    }
                }
            }
        }
    }

    .home-content {
        display: flex;
        flex-direction: column;
        flex-wrap: nowrap;
        gap: 2rem;
        /*height: 100dvh;
        overflow-y: auto;
        scroll-snap-type: y mandatory;*/

        .highlighted-series {
            /*height: 100dvh;
            margin-bottom: unset;
            padding-block: 6dvh;
            scroll-snap-align: start;*/
        }

        .series-group {
            margin-top: unset;

            h2 {
                text-align: left;
            }

            .wrapper {
                .content {
                    overflow-x: auto;
                    scroll-snap-type: x mandatory;
                    /*width: 100%;*/

                    .card {
                        scroll-snap-align: start;

                        .series-name {
                            background-color: cadetblue;
                            border-radius: 0 0 .5rem .5rem;
                            align-items: center;
                            justify-content: center;
                        }
                    }
                }
            }
        }
    }
}

@media (width <= 52rem) {
    .home {
        .series-status {
            flex-direction: column;

            .status-items {
                padding: 1rem;

                .status-item {
                    .name {
                        font-size: max(.75rem, 2vw);
                    }

                    .count {
                        font-size: max(2rem, 5vw);
                    }
                }
            }
        }
    }
}

@media (orientation: portrait) {
    .home {
        .highlighted-series {
            flex-direction: column;
            height: auto;
            width: 90vw;

            .poster {
                aspect-ratio: 2 / 3;
                height: 64dvh;
                max-width: 90vw;
                width: auto;
            }

            .details {
                height: auto;
                width: 90vw;

                .name {
                    font-size: 3rem;
                    line-height: 1.25em;
                }

                .overview {
                    align-items: flex-start;
                    display: flex;
                    font-size: 1.5rem;
                    max-height: unset;
                    line-height: 1.25em;
                    overflow-y: auto;
                }
            }
        }
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.series-group {
    align-items: flex-start;
    //background-color: var(--ardoise-80);
    border-radius: .25rem;
    color: var(--ardoise-10);
    display: flex;
    flex-direction: column;
    font-weight: 300;
    justify-content: flex-start;
    margin-top: 2rem;
    //padding: 1rem;
    text-align: center;
    transition: background-color .250ms, color .250ms;

    .header {
        align-items: center;
        display: flex;
        gap: 1rem;
        justify-content: flex-start;
        padding-block: 0;
        padding-inline: 0;
        width: 100%;

        .logo {
            height: 2em;
            width: 2em;

            img {
                border-radius: .25rem;
                height: 2rem;
                object-fit: cover;
                width: 2rem;
            }
        }

        label {
            gap: 1rem;

            select {
                color: var(--ardoise-10);
            }
        }
    }

    &.user {
        margin-block-start: 1rem;

        .wrapper {
            display: flex;
            justify-content: center;
            overflow-x: unset;
            padding-block: unset;

            .content {
                flex-wrap: wrap;
                width: 100%;
            }
        }
    }

    .wrapper {
        display: flex;
        overflow-x: auto;
        width: 100%;

        .content {
            align-items: stretch;
            display: flex;
            gap: 1rem;
            flex-shrink: 0;
            justify-content: flex-start;
            margin: 0 auto;
            padding-block: 1rem;

            &:has(.tmdb) {
                align-items: stretch;
            }

            &.center {
                width: round(down, 100%, 10.25rem); /* 10rem (card) + 0.25rem (gap) */
            }

            h3 {
                background-color: var(--orange-40);
                border-radius: .25rem;
                padding: .25rem .5rem;
                text-align: left;
                width: 100%;
            }

            .episode-block {
                display: flex;
                gap: .25rem;
                margin-inline-end: .5rem;

                > div:first-child {
                    box-shadow: .25rem 0 .5rem .125rem #0000007f;
                }

                > div:last-child {
                    filter: brightness(.75);
                    margin-block-start: -.25rem;
                    margin-inline-start: clamp(-8rem, calc(-0.1 * max(18rem, 24vmax)), -11rem);
                    transform: rotate(3deg);
                    z-index: -1;
                }
            }
        }
    }
}

.video-background {
    height: calc(900vw / 16);
    /* Used to position the video and content */
    position: relative;
}

.video-background__inner {
    /* Positioned at the top left corner */
    left: 0;
    position: absolute;
    top: 0;

    /* Take full size */
    height: 100%;
    width: 100%;

    /* Hide the scrollbar */
    overflow: hidden;
}

.video-background__video {
    object-fit: cover;

    /* Take full width */
    height: 100%;
    width: 100%;
}

.video-background__content {
    /* Positioned at the top left corner */
    left: 0;
    position: absolute;
    top: 0;

    /* Take full size */
    height: 100%;
    width: 100%;

    /* Center the content */
    align-items: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
