/* ============================================================
   Latch & Lantern :: THE LANGUAGE SWITCHER (before sign-in)
   Built by web/js/lang-switch.js into any [data-lang-switch].

   Loaded AFTER css/marketing.css or css/auth.css and dressed in
   whichever palette that page declared: every colour below is one of
   the tokens both stylesheets define (--ink-2, --ink, --line,
   --line-2, --surface, --accent-rgb, --shadow-rgb). No literals, so
   it is brass on the lantern pages, tomato on a plain one, and right
   in the legal pages' dark scheme without a rule of its own.

   A quiet pill in the footer ("◯ English ⌄") that opens a short card
   of endonyms above itself, the current one ticked. The header variant
   ([data-lang-switch="compact"], "◯ EN") is at the end of the file.
   ============================================================ */

.lang-switch {
    position: relative;
    display: inline-flex;
    vertical-align: middle;
    text-align: left;
}

/* ---------------------------------------------------------- the trigger */

.lang-switch-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 3px 9px 3px 7px;
    min-height: 28px;
    font: inherit;
    font-size: .86rem;
    font-weight: 500;
    line-height: 1.2;
    color: var(--ink-2);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 999px;
    cursor: pointer;
    transition: color .15s ease, border-color .15s ease, background-color .15s ease;
    -webkit-tap-highlight-color: transparent;
}

.lang-switch-btn:hover {
    color: var(--ink);
    border-color: var(--line-2);
}

.lang-switch-open .lang-switch-btn {
    color: var(--ink);
    background: var(--surface);
    border-color: rgba(var(--accent-rgb), .45);
}

.lang-switch-btn:focus-visible {
    outline: 2px solid rgba(var(--accent-rgb), .6);
    outline-offset: 2px;
    border-radius: 999px;
}

.lang-switch svg {
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.lang-switch-globe { width: 14px; height: 14px; opacity: .85; }

.lang-switch-chevron {
    width: 12px;
    height: 12px;
    margin-left: -1px;
    transition: transform .18s ease;
}

.lang-switch-open .lang-switch-chevron { transform: rotate(180deg); }

/* ---------------------------------------------------------- the list */

.lang-switch-list {
    position: absolute;
    z-index: 60;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(calc(-50% + var(--lang-switch-shift, 0px)));
    min-width: 10.5rem;
    margin: 0;
    padding: 5px;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(var(--shadow-rgb), .06),
                0 14px 34px rgba(var(--shadow-rgb), .14);
    animation: lang-switch-in .14s ease-out;
}

/* No room above (a switcher near the top of a short window): open downward. */
.lang-switch-down .lang-switch-list {
    bottom: auto;
    top: calc(100% + 8px);
}

.lang-switch-list[hidden] { display: none; }

.lang-switch-list li { margin: 0; padding: 0; }

/* Two classes, so the footers' own `.mk-foot-links a` / `.au-foot a` rules
   (one class and an element) do not restyle the items. */
.lang-switch .lang-switch-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 7px 10px;
    border-radius: 8px;
    font-size: .92rem;
    font-weight: 500;
    line-height: 1.3;
    color: var(--ink-2);
    text-decoration: none;
    white-space: nowrap;
}

.lang-switch .lang-switch-item:hover,
.lang-switch .lang-switch-item:focus-visible {
    color: var(--ink);
    background: rgba(var(--accent-rgb), .09);
}

.lang-switch .lang-switch-item:focus-visible {
    outline: 2px solid rgba(var(--accent-rgb), .6);
    outline-offset: -2px;
    border-radius: 8px;
}

.lang-switch .lang-switch-item[aria-current="true"] {
    color: var(--ink);
    font-weight: 600;
}

.lang-switch .lang-switch-check {
    width: 14px;
    height: 14px;
    stroke: rgb(var(--accent-rgb));
    stroke-width: 1.8;
}

/* ---------------------------------------------------------- the header variant
   "◯ EN" at the right end of .mk-nav-links. It is dressed as one of that row's
   links — same type size and line height (so the same 40px height), no
   border, the row's hover wash — so it reads as part of the nav rather than
   a widget dropped into it. --paper-2 is marketing.css's; the fallback is
   for a page that ever mounts it without that sheet. */

.mk-nav-lang { display: inline-flex; flex: none; }

.lang-switch-compact .lang-switch-btn {
    gap: 5px;
    padding: 8px 10px;
    /* A nav link's box: .93rem at line-height 1.6 plus 8px above and below. The
       button's children are flex items, so its own line-height does not set it. */
    min-height: calc(.93rem * 1.6 + 16px);
    font-size: .93rem;
    line-height: 1.6;
    border: 0;
}

.lang-switch-compact .lang-switch-btn:hover,
.lang-switch-compact.lang-switch-open .lang-switch-btn {
    color: var(--ink);
    background: var(--paper-2, var(--surface));
}

.lang-switch-compact .lang-switch-globe { width: 16px; height: 16px; opacity: 1; }

.lang-switch-code {
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .04em;
    font-variant-numeric: tabular-nums;
}

/* Below the button, right edges aligned: it is the last thing in the header. */
.lang-switch-compact .lang-switch-list {
    top: calc(100% + 6px);
    bottom: auto;
    left: auto;
    right: 0;
    transform: translateX(var(--lang-switch-shift, 0px));
    animation-name: lang-switch-in-down;
}

@media (max-width: 420px) {
    /* The row is down to the wordmark and the two doors here (marketing.css). The
       globe alone is the control; its name still says "Language: English". */
    .lang-switch-compact .lang-switch-btn { padding: 8px 5px; min-height: calc(.82rem * 1.6 + 16px); }
    .lang-switch-compact .lang-switch-code { display: none; }
}

@media (max-width: 359px) {
    .lang-switch-compact .lang-switch-btn { padding: 8px 4px; min-height: calc(.78rem * 1.6 + 16px); }
}

@keyframes lang-switch-in {
    from { opacity: 0; translate: 0 4px; }
    to   { opacity: 1; translate: 0 0; }
}

@keyframes lang-switch-in-down {
    from { opacity: 0; translate: 0 -4px; }
    to   { opacity: 1; translate: 0 0; }
}

@media (prefers-reduced-motion: reduce) {
    .lang-switch-btn,
    .lang-switch-chevron { transition: none; }
    .lang-switch-list,
    .lang-switch-compact .lang-switch-list { animation: none; }
}
