/*
 * The language switcher (components/language_switcher.html) and the
 * suggestion bar (components/language_suggest.html).
 *
 * Linked on every page by components/i18n_head.html, also on the public
 * pages that load neither base.css nor header.css: every colour has the
 * dark theme's value as its fallback. The switcher's lists open in place
 * (menu, mobile) or over the page (pill), and the bar floats above it, so
 * nothing on the page moves when they appear. Touch targets are at least
 * 44 px; with a mouse, the menu and the pill keep their neighbours' height.
 * Logical properties (inline-start/end) keep the layout right in a
 * right-to-left language.
 */

/* ==================== Shared ==================== */

.lang-switcher {
    --lang-accent: var(--accent-purple, #aa66ff);
    --lang-accent-dim: var(--accent-purple-dim, rgba(170, 102, 255, 0.15));
    --lang-card: var(--bg-card, #1a1a24);
    --lang-hover: var(--bg-hover, #22222e);
    --lang-border: var(--border-color, #2a2a3a);
    --lang-text: var(--text-primary, #ffffff);
    --lang-text-dim: var(--text-secondary, #a0a0b0);
    position: relative;
    font-family: inherit;
}

.lang-switcher-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.lang-switcher-summary {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 44px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

/* The disclosure triangle: the chevron stands in for it. */
.lang-switcher-summary::-webkit-details-marker { display: none; }
.lang-switcher-summary::marker { content: ''; }

.lang-switcher-icon { flex-shrink: 0; }

.lang-switcher-current {
    margin-inline-start: auto;
    color: var(--lang-text-dim);
    white-space: nowrap;
}

.lang-switcher-chevron {
    flex-shrink: 0;
    opacity: 0.6;
    transition: transform 0.2s ease;
}

.lang-switcher[open] > .lang-switcher-summary .lang-switcher-chevron {
    transform: rotate(180deg);
}

.lang-switcher-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0 0.75rem;
    border-radius: 8px;
    color: var(--lang-text-dim);
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.15s ease, color 0.15s ease;
}

.lang-switcher-item:hover {
    background: var(--lang-hover);
    color: var(--lang-text);
}

.lang-switcher-item.is-active {
    color: var(--lang-accent);
    font-weight: 600;
}

.lang-switcher-check {
    margin-inline-start: auto;
    flex-shrink: 0;
}

.lang-switcher-beta {
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(255, 204, 0, 0.15);
    color: var(--accent-yellow, #ffcc00);
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.lang-switcher-summary:focus-visible,
.lang-switcher-item:focus-visible,
.lang-suggest a:focus-visible,
.lang-suggest button:focus-visible {
    outline: 2px solid var(--lang-accent, #aa66ff);
    outline-offset: 2px;
}

/* For screen readers only: the pill's "Language". */
.lang-visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==================== Menu: the header's user menu ==================== */
/* The summary also has .user-dropdown-item (header.css), so it looks like
   its neighbours; the list opens below it, inside the menu. */

.lang-switcher--menu .lang-switcher-list {
    padding: 0.15rem 0 0.25rem;
    padding-inline-start: 1.6rem;
}

.lang-switcher--menu[open] > .lang-switcher-summary {
    color: var(--lang-text);
}

/* ==================== Mobile: the mobile navigation ==================== */
/* The summary also has .mobile-nav-link (header.css). */

.lang-switcher--mobile .lang-switcher-summary {
    width: 100%;
    gap: 0.75rem;
}

/* The names start where "Language" does: past the link's padding and icon. */
.lang-switcher--mobile .lang-switcher-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.25rem 0;
    padding-inline-start: calc(1rem + 24px);
}

.lang-switcher--mobile .lang-switcher-item {
    font-size: 0.95rem;
    border-radius: 10px;
}

/* ==================== Pill: a page header ==================== */

.lang-switcher--pill {
    display: inline-block;
}

.lang-switcher--pill > .lang-switcher-summary {
    gap: 0.45rem;
    padding: 0 0.85rem;
    border: 1px solid var(--lang-border);
    border-radius: 999px;
    background: var(--lang-card);
    color: var(--lang-text-dim);
    font-size: 0.85rem;
    font-weight: 500;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.lang-switcher--pill > .lang-switcher-summary:hover,
.lang-switcher--pill[open] > .lang-switcher-summary {
    border-color: var(--lang-accent);
    color: var(--lang-text);
}

.lang-switcher--pill .lang-switcher-current {
    margin-inline-start: 0;
    color: inherit;
}

.lang-switcher--pill .lang-switcher-list {
    position: absolute;
    top: calc(100% + 6px);
    inset-inline-end: 0;
    z-index: 1001;
    min-width: 190px;
    max-height: min(70vh, 420px);
    overflow-y: auto;
    padding: 0.4rem;
    border: 1px solid var(--lang-border);
    border-radius: 12px;
    background: var(--lang-card);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

/* A phone: a pill with neighbours after it (other than the switcher's own
   script) starts its row (the help's bar for visitors, whose row wraps
   under the brand), so its list opens towards them, not off the screen; a
   pill at the end of its row (the landing) keeps opening towards the start. */
@media (max-width: 720px) {
    .lang-switcher--pill:has(~ :not(script)) .lang-switcher-list {
        inset-inline-start: 0;
        inset-inline-end: auto;
    }
}

/* ==================== Footer: a page footer ==================== */

/* On a narrow screen the list wraps below the globe, centred. */
.lang-switcher--footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0 0.35rem;
    color: var(--lang-text-dim);
}

.lang-switcher--footer .lang-switcher-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
}

.lang-switcher--footer .lang-switcher-item {
    padding: 0 0.6rem;
}

.lang-switcher--footer .lang-switcher-check { display: none; }

.lang-switcher--footer .lang-switcher-item.is-active {
    color: var(--lang-text);
}

/* With a mouse: the header's menu rows and the pill as tall as their neighbours. */
@media (hover: hover) and (pointer: fine) {
    .lang-switcher--menu > .lang-switcher-summary,
    .lang-switcher--menu .lang-switcher-item {
        min-height: 34px;
    }
    .lang-switcher--pill > .lang-switcher-summary {
        min-height: 36px;
    }
    .lang-switcher--pill .lang-switcher-item,
    .lang-switcher--footer .lang-switcher-item {
        min-height: 36px;
    }
}

/* ==================== The suggestion bar ==================== */
/* Floats at the bottom, centred and as wide as its line (never across the
   floating buttons in the bottom corners); on a phone across the width,
   above those buttons on the signed-in pages that have them (raised). */

.lang-suggest {
    position: fixed;
    inset-inline: 0;
    bottom: 24px;
    z-index: 9700;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: max-content;
    max-width: min(640px, calc(100vw - 192px));
    margin-inline: auto;
    padding: 0.4rem;
    padding-inline: 0.9rem 0.4rem;
    border: 1px solid var(--border-color, #2a2a3a);
    border-radius: 14px;
    background: var(--bg-card, #1a1a24);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    color: var(--text-primary, #ffffff);
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 0.9rem;
    line-height: 1.35;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.lang-suggest.is-visible {
    opacity: 1;
    transform: none;
}

.lang-suggest-icon {
    display: flex;
    flex-shrink: 0;
    color: var(--accent-purple, #aa66ff);
}

.lang-suggest-name {
    flex-shrink: 0;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    background: var(--accent-purple-dim, rgba(170, 102, 255, 0.15));
    color: var(--accent-purple, #aa66ff);
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.lang-suggest-text {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    color: var(--text-secondary, #a0a0b0);
}

.lang-suggest-switch {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 1rem;
    border-radius: 10px;
    background: var(--gradient-purple, linear-gradient(135deg, #aa66ff 0%, #8844cc 100%));
    color: #ffffff;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.lang-suggest-switch:hover { filter: brightness(1.1); }

.lang-suggest-dismiss {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary, #a0a0b0);
    cursor: pointer;
}

.lang-suggest-dismiss:hover {
    background: var(--bg-hover, #22222e);
    color: var(--text-primary, #ffffff);
}

@media (hover: hover) and (pointer: fine) {
    .lang-suggest-switch { min-height: 36px; }
    .lang-suggest-dismiss { width: 36px; height: 36px; }
}

/* A phone: the language and the sentence on one row (dismiss at its end),
   Switch across the row below. */
@media (max-width: 720px) {
    .lang-suggest {
        inset-inline: 16px;
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas:
            "name text dismiss"
            "switch switch switch";
        gap: 0.4rem 0.6rem;
        width: auto;
        max-width: none;
        margin-inline: 0;
        padding: 0.5rem;
        padding-inline: 0.75rem 0.4rem;
    }
    .lang-suggest--raised {
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    }
    .lang-suggest-icon { display: none; }
    .lang-suggest-name { grid-area: name; }
    .lang-suggest-text { grid-area: text; }
    .lang-suggest-switch { grid-area: switch; }
    .lang-suggest-dismiss { grid-area: dismiss; }
}

@media (prefers-reduced-motion: reduce) {
    .lang-suggest,
    .lang-switcher-chevron,
    .lang-switcher-item {
        transition: none;
    }
}

@media print {
    .lang-suggest { display: none; }
}
