/* Language picker — ported to the new design's tokens.

   The live /i18n.css could not be reused as-is: it is built for the old dark
   theme (#121214 panel, white text at various opacities) and would render a
   dark dropdown on this cream page. The class contract is kept identical
   (.lang-pick / .lang-btn / .lang-menu / a.on), so i18n.js drives this
   unchanged; only the paint differs. Visual language follows .nav__drop:
   paper fill, 2px ink border, hard orange offset shadow.

   PLACEMENT. This sits in .nav__in as a direct sibling of .menu-btn, not
   inside .nav__main — .nav__main is `display:none` below 1061px (site.css),
   which is exactly why the control used to disappear on phones entirely.
   .menu-btn supplies its own `margin-left:auto` to reach the right edge when
   .nav__main is hidden; .lang-pick needs the same push at that breakpoint so
   it travels there with the hamburger instead of getting stranded next to
   the logo. At wider viewports .nav__main's own margin-left:auto already
   pushes this whole tail group (nav__main, lang-pick, .btn, menu-btn)
   to the right as one unit, so no desktop-specific rule is needed here. */

.lang-pick { position: relative; }

@media (max-width: 1060px) {
  /* .menu-btn (site.css) carries its own unconditional margin-left:auto, for
     pages where no picker renders at all (fewer than 2 locales available —
     see picker()'s early return). If .lang-pick ALSO got margin-left:auto,
     flexbox splits the free space evenly between both auto margins, leaving
     a visible gap between the language button and the hamburger instead of
     the two sitting together. Zeroing menu-btn's margin specifically when a
     picker immediately precedes it avoids that, while leaving menu-btn's own
     auto margin intact for the no-picker case. */
  .lang-pick { margin-inline-start: auto; }
  /* .nav__in's gap:32px (site.css) is meant to separate distinct nav groups,
     not two sibling buttons meant to read as one matched pair. flexbox gap
     and an item's own margin are ADDITIVE, not alternatives — a naive
     margin-inline-start:10px here measured as 42px in practice (32 + 10).
     Netting out to an actual 10px needs a negative margin equal to
     (target - gap). Logical property: DOM order is unchanged between LTR
     and RTL (.lang-pick still precedes .menu-btn in markup), so
     margin-inline-start still targets the correct sibling edge either way. */
  .lang-pick + .menu-btn { margin-inline-start: calc(10px - 32px); }
}

/* Styled to match .menu-btn exactly (same border, fill, height, type
   weight), so the two sit as a visually matched pair next to each other —
   this was a plain text+chevron link before, which read as noticeably
   weaker next to "Menu"'s solid bordered box. */
.lang-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px 0 16px;
  font: 650 1rem var(--display);
  font-stretch: 104%;
  color: var(--ink);
  background: var(--ivory);
  border: 2px solid var(--ink);
  cursor: pointer;
  white-space: nowrap;
}

.lang-btn:hover { background: var(--sunken); }

.lang-btn::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform .15s ease;
  flex-shrink: 0;
}

.lang-btn[aria-expanded="true"]::after { transform: translateY(1px) rotate(-135deg); }
.lang-btn:focus-visible { outline: 2px solid var(--orange); outline-offset: 3px; }

.lang-menu {
  position: absolute;
  /* Anchored from the END (right in LTR, automatically the left in RTL via
     this logical property) rather than the start: the button now sits at
     the far edge of the header next to the hamburger, so a start-anchored
     panel would overflow off the right side of narrow viewports. */
  inset-inline-end: 0;
  top: calc(100% + 14px);
  min-width: 200px;
  /* Capped well under the shortest hero-copy/robot gap measured across all 15
     locales at mobile widths (~377px on es/it/ja/pt/tr) so the open panel
     never reaches into the robot artwork below it, regardless of how long
     that locale's translated hero copy runs. The list already needs
     overflow-y:auto to fit 15 languages at any cap, so shrinking this further
     doesn't newly introduce scrolling. */
  max-height: min(60vh, 320px);
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 8px 0;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 6px 6px 0 var(--orange);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity .15s ease, transform .15s ease, visibility .15s;
  z-index: 60;
}

.lang-pick.open .lang-menu { opacity: 1; visibility: visible; transform: none; }

.lang-menu li { margin: 0; }

.lang-menu a {
  display: block;
  padding: 7px 16px;
  font-family: var(--display);
  font-size: .95rem;
  color: var(--ink);
  text-decoration: none;
}

.lang-menu a:hover { background: var(--sunken); }
.lang-menu a:focus-visible { outline: 2px solid var(--orange); outline-offset: -2px; }

.lang-menu a.on { font-weight: 600; }
.lang-menu a.on::after { content: " ✓"; color: var(--orange-text); }

@media (max-width: 420px) {
  /* Below this, min-width:200px plus the 2px border can start crowding a
     phone's own viewport edges given the button sits flush right. Widen the
     panel's reach slightly rather than letting it clip. */
  .lang-menu { min-width: min(240px, calc(100vw - 32px)); }
}

@media (prefers-reduced-motion: reduce) {
  .lang-menu { transition: none; }
}
