/* ==========================================================================
   The row of languages (layouts/shared/language-row): the languages every
   course is studied in, as one row of cards. It closes the home page of an
   account and, on the public pages, the section under the course cards. One
   sheet for every page that shows it, output once per request.

   A card is the card of the language menu and of the dialog of a course
   card: the flag as an enamel disc cut from the square symbol of
   images/flags/language-flags.svg, the name the language gives itself, its
   English name. The row holds whole cards only: its own width says how many
   (--lr-per), each column is that share of the row and the row snaps to the
   start of a card, so no card is ever cut by an edge. The row is never wider
   than its cards at 180px, so a card is never left half empty: a narrower
   row stands in the middle of its place.

       the place          cards   a card      the arrows
       972px and wider    5       164-166px   at the two ends of the row
       812px to 972px     4       167-180px   at the two ends of the row
       640px to 812px     3       169-180px   at the two ends of the row
       512px to 640px     3       164-180px   under the row
       300px to 512px     2       145-180px   under the row, the cards set closer
       under 300px        1       up to 180px at the two ends of the row

   The thin line shows how far the row has moved: between the arrows where
   they stand under the row, under the middle of the row where they stand at
   its ends. A card is read and never pressed: the language is chosen in the
   language menu.

   Everything reads from the tokens below; html.dark swaps them, so the dark
   look is the same sheet (the place that carries the row says data-dm-skip
   where the dashboard's theme script would repaint it). The sizes are fixed,
   like the course cards the row stands under: a wide screen gives it margin,
   never bigger cards. The class is doubled where a page sets one face on
   everything inside it.
   ========================================================================== */

.lang-row {
    --lr-ink: #0b1220;
    --lr-soft: #3f4d66;
    --lr-blue: #2563eb;
    --lr-blue-deep: #1d4ed8;
    --lr-line: rgba(30, 58, 138, 0.1);
    --lr-ease: cubic-bezier(0.22, 1, 0.36, 1);
    /* the names of the languages: Inter, then the faces that hold the scripts it does not */
    --lr-names: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', 'Nirmala UI', 'Leelawadee UI', sans-serif;
    --lr-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    --lr-card: rgba(255, 255, 255, 0.88);
    --lr-card-line: rgba(30, 58, 138, 0.11);
    --lr-card-shadow: 0 1px 2px rgba(11, 31, 58, 0.05);
    --lr-picked-base: #ffffff;
    --lr-picked: linear-gradient(135deg, rgba(37, 99, 235, 0.15) 0%, rgba(37, 99, 235, 0.05) 100%);
    --lr-picked-line: rgba(37, 99, 235, 0.52);

    --lr-flag-edge: rgba(11, 18, 32, 0.14);
    --lr-flag-ring: #ffffff;
    --lr-flag-drop: 0 6px 12px -8px rgba(11, 31, 58, 0.5);

    --lr-disc: #ffffff;
    --lr-disc-line-hover: rgba(37, 99, 235, 0.45);
    --lr-disc-shadow: 0 10px 22px -16px rgba(30, 58, 138, 0.6);
    --lr-disc-shadow-hover: 0 14px 26px -16px rgba(37, 99, 235, 0.6);

    --lr-track: rgba(30, 58, 138, 0.12);
    --lr-thumb: linear-gradient(90deg, #2563eb 0%, #1d4ed8 100%);
    --lr-focus: rgba(37, 99, 235, 0.22);

    container: lang-row / inline-size;
    box-sizing: border-box;
    width: 100%;
    font-family: var(--lr-body);
    color: var(--lr-ink);
    text-align: start;
}

html.dark .lang-row {
    --lr-ink: #eef3fb;
    --lr-soft: #b4c0d6;
    --lr-blue: #60a5fa;
    --lr-blue-deep: #93c5fd;
    --lr-line: rgba(255, 255, 255, 0.12);

    --lr-card: rgba(255, 255, 255, 0.05);
    --lr-card-line: rgba(255, 255, 255, 0.09);
    --lr-card-shadow: none;
    --lr-picked-base: #14233f;
    --lr-picked: linear-gradient(135deg, rgba(59, 130, 246, 0.34) 0%, rgba(59, 130, 246, 0.12) 100%);
    --lr-picked-line: rgba(96, 165, 250, 0.7);

    --lr-flag-edge: rgba(255, 255, 255, 0.2);
    --lr-flag-ring: rgba(255, 255, 255, 0.9);
    --lr-flag-drop: 0 6px 12px -8px rgba(0, 0, 0, 0.8);

    --lr-disc: rgba(255, 255, 255, 0.06);
    --lr-disc-line-hover: rgba(96, 165, 250, 0.6);
    --lr-disc-shadow: none;
    --lr-disc-shadow-hover: 0 14px 26px -16px rgba(0, 0, 0, 0.85);

    --lr-track: rgba(255, 255, 255, 0.14);
    --lr-thumb: linear-gradient(90deg, #60a5fa 0%, #3b82f6 100%);
    --lr-focus: rgba(96, 165, 250, 0.32);
}

/* ---- the row, its two arrows and its line: one grid ---- */
.lang-row__in {
    --lr-per: 2;
    --lr-gap: 10px;
    --lr-nav: 44px;
    --lr-flag: 34px;
    /* the arrows under the row: they take none of its width and the line runs between them */
    --lr-side: 0px;
    --lr-bar: 100%;
    --lr-areas: "list list list" "prev bar next";

    display: grid;
    grid-template-columns: var(--lr-nav) minmax(0, 1fr) var(--lr-nav);
    grid-template-areas: var(--lr-areas);
    align-items: center;
    column-gap: 12px;
    row-gap: 16px;
    box-sizing: border-box;
    width: 100%;
    /* a card is never wider than 180px, so the row is never wider than its cards */
    max-width: calc(var(--lr-per) * 180px + (var(--lr-per) - 1) * var(--lr-gap) + var(--lr-side));
    margin: 0 auto;
}

/* The list scrolls by itself (a swipe, a trackpad, the keyboard) and snaps to
   the start of a card. Its columns are a whole share of its width, so what
   it shows is always whole cards. The padding above and under it is the room
   of the hairline shadow, taken back by the margin so the arrows centre on
   the cards. */
.lang-row__list {
    grid-area: list;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: calc((100% - (var(--lr-per) - 1) * var(--lr-gap)) / var(--lr-per));
    /* fewer cards than the row holds stand in its middle */
    justify-content: safe center;
    column-gap: var(--lr-gap);
    box-sizing: border-box;
    min-width: 0;
    margin: -4px 0;
    padding: 4px 0;
    list-style: none;
    border-radius: 18px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.lang-row__list::-webkit-scrollbar {
    display: none;
}

.lang-row__list:focus {
    outline: 0;
}

.lang-row__list:focus-visible {
    outline: 2px solid var(--lr-blue);
    outline-offset: 2px;
}

/* A language: a white glass card. It is read, never pressed, so it neither
   lifts nor points. */
.lang-row__item {
    scroll-snap-align: start;
    position: relative;
    display: flex;
    align-items: center;
    gap: 11px;
    box-sizing: border-box;
    min-width: 0;
    min-height: 56px;
    margin: 0;
    padding: 7px 11px 7px 9px;
    border: 1px solid var(--lr-card-line);
    border-radius: 16px;
    background-color: var(--lr-card);
    box-shadow: var(--lr-card-shadow);
    list-style: none;
    text-align: start;
}

.lang-row__item::before,
.lang-row__item::marker {
    content: none;
}

/* the language the reader uses */
.lang-row__item.is-current {
    background-color: var(--lr-picked-base);
    background-image: var(--lr-picked);
    border-color: var(--lr-picked-line);
}

.lang-row__mark {
    position: relative;
    flex: 0 0 auto;
    display: block;
}

/* a flag: a disc cut from the square symbol, a hairline so white never melts
   into white, a white ring that sets it off the card */
.lang-row__flag {
    position: relative;
    display: block;
    width: var(--lr-flag);
    height: var(--lr-flag);
    border-radius: 50%;
    overflow: hidden;
    isolation: isolate;
    background: #e8eefb;
    box-shadow: 0 0 0 2px var(--lr-flag-ring), 0 0 0 3px var(--lr-line), var(--lr-flag-drop);
}

.lang-row__flag svg {
    display: block;
    width: 100%;
    height: 100%;
}

.lang-row__flag::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1px var(--lr-flag-edge);
    pointer-events: none;
}

/* a language of two countries wears both flags: two smaller discs in the room of one */
.lang-row__mark--pair {
    width: var(--lr-flag);
    height: var(--lr-flag);
}

.lang-row__mark--pair .lang-row__flag {
    position: absolute;
    width: calc(var(--lr-flag) * 0.7);
    height: calc(var(--lr-flag) * 0.7);
}

.lang-row__mark--pair .lang-row__flag:first-child {
    top: 0;
    left: 0;
    z-index: 1;
}

.lang-row__mark--pair .lang-row__flag:last-child {
    right: 0;
    bottom: 0;
}

/* the tick of the language menu, on the lower right of the flag in use */
.lang-row__item.is-current .lang-row__mark::after {
    content: '';
    position: absolute;
    right: -6px;
    bottom: -5px;
    z-index: 2;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l5 5 9-10'/%3E%3C/svg%3E") center / 10px 10px no-repeat,
        linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    box-shadow: 0 0 0 2px var(--lr-picked-base);
}

.lang-row__text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* One line each. Every name of the list has its room at every width
   (measured: the longest, Nederlands, is 91px wide at 16px and 85px at 15px);
   the ellipsis only stands by for a name longer than any of them. */
.lang-row.lang-row .lang-row__native,
.lang-row.lang-row .lang-row__name {
    display: block;
    max-width: 100%;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0;
    text-transform: none;
}

/* a name written from right to left keeps its own order and still starts
   where every other name starts; the padding is the room of a tall script */
.lang-row.lang-row .lang-row__native {
    margin-block: -3px;
    padding-block: 3px;
    unicode-bidi: isolate;
    font-family: var(--lr-names);
    font-size: 16px;
    font-weight: 600;
    line-height: 22px;
    color: var(--lr-ink);
}

.lang-row.lang-row .lang-row__item.is-current .lang-row__native {
    font-weight: 700;
}

.lang-row.lang-row .lang-row__name {
    font-family: var(--lr-body);
    font-size: 14px;
    font-weight: 500;
    line-height: 18px;
    color: var(--lr-soft);
}

/* said to a screen reader; the tick says it to the eye */
.lang-row__used {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ---- the arrows: a white disc, a calm lift for a pointer that can hover and
   nothing that sticks after a tap ---- */
.lang-row.lang-row .lang-row__nav {
    -webkit-appearance: none;
    appearance: none;
    display: grid;
    place-items: center;
    box-sizing: border-box;
    width: var(--lr-nav);
    min-width: 0;
    height: var(--lr-nav);
    margin: 0;
    padding: 0;
    border: 1px solid var(--lr-line);
    border-radius: 50%;
    background: var(--lr-disc);
    box-shadow: var(--lr-disc-shadow);
    color: var(--lr-blue-deep);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition:
        transform 0.25s var(--lr-ease),
        box-shadow 0.25s var(--lr-ease),
        border-color 0.25s var(--lr-ease),
        opacity 0.25s var(--lr-ease);
}

.lang-row__nav--prev {
    grid-area: prev;
}

.lang-row__nav--next {
    grid-area: next;
}

.lang-row__nav svg {
    display: block;
    width: 20px;
    height: 20px;
    transition: transform 0.25s var(--lr-ease);
}

.lang-row.lang-row .lang-row__nav:active {
    transform: scale(0.96);
}

.lang-row.lang-row .lang-row__nav:focus {
    outline: 0;
}

.lang-row.lang-row .lang-row__nav:focus-visible {
    border-color: var(--lr-blue);
    box-shadow: 0 0 0 4px var(--lr-focus), var(--lr-disc-shadow);
}

/* the end of the row: the arrow that leads nowhere steps back */
.lang-row.lang-row .lang-row__nav[aria-disabled="true"] {
    opacity: 0.38;
    box-shadow: none;
    cursor: default;
    transform: none;
}

/* ---- how far the row has moved: the share of the list it shows, where it
   stands in it (--lr-share and --lr-at, written by the script) ---- */
.lang-row__bar {
    grid-area: bar;
    justify-self: center;
    display: block;
    width: min(var(--lr-bar), 100%);
    height: 4px;
    border-radius: 999px;
    background: var(--lr-track);
    overflow: hidden;
}

.lang-row__bar::before {
    --lr-thumb-width: max(16px, calc(var(--lr-share, 0.14) * 100%));
    content: '';
    display: block;
    width: var(--lr-thumb-width);
    height: 100%;
    margin-inline-start: calc((100% - var(--lr-thumb-width)) * var(--lr-at, 0));
    border-radius: inherit;
    background: var(--lr-thumb);
}

/* a row that shows every card it has needs neither the arrows nor the line */
.lang-row.is-still .lang-row__in {
    row-gap: 0;
}

.lang-row.lang-row.is-still .lang-row__nav,
.lang-row.is-still .lang-row__bar {
    display: none;
}

@media (hover: hover) and (pointer: fine) {
    .lang-row.lang-row .lang-row__nav:not([aria-disabled="true"]):hover {
        transform: translateY(-1px);
        border-color: var(--lr-disc-line-hover);
        box-shadow: var(--lr-disc-shadow-hover);
    }

    .lang-row__nav--prev:not([aria-disabled="true"]):hover svg {
        transform: translateX(-2px);
    }

    .lang-row__nav--next:not([aria-disabled="true"]):hover svg {
        transform: translateX(2px);
    }
}

/* ==========================================================================
   The width of the row says how many cards it holds
   ========================================================================== */

/* the narrowest screen: one card between the arrows */
@container lang-row (max-width: 299.98px) {
    .lang-row__in {
        --lr-per: 1;
        --lr-side: calc(2 * var(--lr-nav) + 24px);
        --lr-bar: 140px;
        --lr-areas: "prev list next" "bar bar bar";
    }
}

/* a phone: two cards, set closer so every name keeps its room */
@container lang-row (min-width: 300px) and (max-width: 511.98px) {
    .lang-row__in {
        --lr-flag: 30px;
    }

    .lang-row__item {
        gap: 9px;
        padding: 7px 8px;
    }

    .lang-row.lang-row .lang-row__native {
        font-size: 15px;
    }
}

@container lang-row (min-width: 512px) {
    .lang-row__in {
        --lr-per: 3;
    }
}

/* the arrows at the two ends of the row: they and the 12px beside each take
   their share of its width, and the line stands under its middle */
@container lang-row (min-width: 640px) {
    .lang-row__in {
        --lr-side: calc(2 * var(--lr-nav) + 24px);
        --lr-bar: 140px;
        --lr-areas: "prev list next" "bar bar bar";
    }
}

@container lang-row (min-width: 812px) {
    .lang-row__in {
        --lr-per: 4;
    }
}

@container lang-row (min-width: 972px) {
    .lang-row__in {
        --lr-per: 5;
    }
}

@media (prefers-reduced-motion: reduce) {
    .lang-row.lang-row .lang-row__nav,
    .lang-row__nav svg {
        transition: none;
    }
}
