/*
 * The language switch, shared by every page. It sits beside the actions in the
 * header and stays quieter than them: a setting, not an offer.
 */

.lang {
  position: relative;
  display: inline-flex;
}

/* ── Button ──────────────────────────────────────────────────────────────── */

.lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border-primary);
  border-radius: 10px;
  background: transparent;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition:
    color 0.18s,
    border-color 0.18s,
    background 0.18s;
}
.lang-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-primary);
}

.lang-btn > svg:first-child {
  width: 15px;
  height: 15px;
  flex: none;
}

/* The endonym is set in its own script; 中文 and हिन्दी need more leading than
   Latin letters or the line box clips them. */
.lang-now {
  line-height: 1.6;
  white-space: nowrap;
}

.lang-chev {
  width: 12px;
  height: 12px;
  flex: none;
  opacity: 0.55;
  transition: transform 0.2s;
}
.lang-btn[aria-expanded="true"] .lang-chev {
  transform: rotate(180deg);
}

/* ── Menu ────────────────────────────────────────────────────────────────── */

.lang-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 200;
  min-width: 208px;
  padding: 6px;
  border: 1px solid var(--border-primary);
  border-radius: 14px;
  background: var(--bg-card);
  /* A tight shadow for the edge, a wide one for the height. */
  box-shadow:
    0 1px 2px rgba(21, 24, 26, 0.06),
    0 18px 44px -18px rgba(21, 24, 26, 0.3);

  transform-origin: top right;
  opacity: 0;
  transform: translateY(-6px) scale(0.97);
  transition:
    opacity 0.18s ease,
    transform 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.lang-menu[data-open="true"] {
  opacity: 1;
  transform: none;
}

.lang-menu button {
  display: grid;
  align-items: center;
  gap: 0 10px;
  grid-template-columns: 1fr auto;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 10px;
  background: none;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: var(--text-primary);

  /* Entries arrive staggered; the script sets `--i` per entry. */
  opacity: 0;
  transform: translateY(4px);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease,
    background 0.14s;
}
.lang-menu[data-open="true"] button {
  opacity: 1;
  transform: none;
  transition-delay: calc(var(--i) * 28ms);
}
.lang-menu button:hover {
  background: var(--bg-tertiary);
}

.lang-native {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
}
/* The English name below, for a machine that lacks the native script's font. */
.lang-en {
  grid-column: 1;
  grid-row: 2;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.lang-tick {
  grid-column: 2;
  grid-row: 1 / span 2;
  width: 15px;
  height: 15px;
  opacity: 0;
  transform: scale(0.6);
  transition:
    opacity 0.2s,
    transform 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.4);
}
.lang-menu button[aria-current="true"] .lang-tick {
  opacity: 1;
  transform: none;
}
.lang-menu button[aria-current="true"] .lang-native {
  font-weight: 600;
}

/* ── Switching ───────────────────────────────────────────────────────────── */

/*
 * Nearly every line changes length on a switch. A short blur turns the jump into
 * a movement. Only opacity and filter, nothing that reflows.
 */
.lang-swapping body {
  opacity: 0.35;
  filter: blur(2px);
}
body {
  transition:
    opacity 0.15s ease,
    filter 0.15s ease;
}

/*
 * First load: hidden by opacity until the dictionary is applied, so nobody reads
 * the source language for a moment first. The script removes the class after at
 * most 700 ms, even when the dictionary never arrives.
 */
.lang-loading body {
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .lang-menu,
  .lang-menu button,
  .lang-tick,
  .lang-chev,
  body {
    transition: none;
  }
  .lang-swapping body {
    opacity: 1;
    filter: none;
  }
}

/* ── Narrow screens ──────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  /* On a phone the name goes and the globe stays. */
  .lang-now,
  .lang-chev {
    display: none;
  }
  .lang-btn {
    padding: 0 9px;
  }
  .lang-menu {
    right: 0;
    min-width: 190px;
  }
}

/* ── Note on the legal pages ─────────────────────────────────────────────── */

/* Terms, withdrawal policy, privacy policy and imprint stay German: an
   unreviewed translation of a legal text helps nobody. */
.lang-legal-note {
  max-width: 760px;
  margin: 0 auto 22px;
  padding: 12px 15px;
  border: 1px solid var(--border-primary);
  border-radius: 11px;
  background: var(--bg-tertiary);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-muted);
}
.lang-legal-note b {
  color: var(--text-primary);
  font-weight: 600;
}
