/* locale.css — index.html + changelog.html both. Loaded after palettes.css
   in both <head>s. Own file rather than folded into site.css: this is one
   large, self-contained concern (content-switching mechanism, a menu
   component, Google Translate chrome), the same reasoning changelog.css's
   own header already gives for its own split. site.css/site.js are left
   completely untouched by this feature.

   Two independent mechanisms, layered:
   1. Static content — [data-locale] spans, shown/hidden per language.
   2. Google Translate — fills every gap: a whole language with no
      hand-authored content at all, or a single string missing inside an
      otherwise-translated language. Never touches anything .notranslate. */

/* ---------- Locale content ---------- */
/* :lang() rather than the [lang="es"] attribute selector, since :lang()
   matches INHERITED and REGIONAL language tags (es-AR, en-GB) where a
   plain attribute selector would silently match nothing; :where() keeps
   specificity at zero so this never has to out-fight a component-level
   override; display:revert (not block) so this works on a <span>, <li>,
   <td> alike.

   A single missing translation, inside an otherwise-translated language,
   falls through to Google Translate — the original English stays as a
   real, visible, non-.notranslate node ([data-i18n-default], deliberately
   NOT [data-locale]) whenever no override exists for the current
   language, and only steps aside via :has() when a real override exists. */
[data-locale] { display: none; }

:where(:lang(es)) [data-locale='es'],
:where(:lang(it)) [data-locale='it'] { display: revert; }

.i18n:where(:lang(es)):has(> [data-locale='es']) > [data-i18n-default],
.i18n:where(:lang(it)):has(> [data-locale='it']) > [data-i18n-default] {
  display: none;
}

/* Hard rule for whoever authors an override span: it must never carry its
   own lang attribute. :lang() matches INHERITED language — a span with
   lang="es" on itself would match :lang(es) unconditionally regardless of
   what html[lang] actually is, breaking the reveal-only-when-selected
   mechanism above. data-locale + notranslate only, nothing else. */

/* ---------- Locale switcher ---------- */
.locale-switcher { position: relative; flex: none; }

.locale-trigger {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; padding: 0;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-subtle); color: var(--muted); cursor: pointer;
  transition: color var(--duration-micro) var(--ease-out-expo),
              border-color var(--duration-micro) var(--ease-out-expo),
              background-color var(--duration-micro) var(--ease-out-expo);
}
.locale-trigger:hover { color: var(--accent); border-color: var(--accent); background: var(--bg); }
.locale-trigger:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.locale-trigger-icon {
  width: 16px; height: 16px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* Anchored popover (same model as the mobile hamburger panel, site.css
   .nav .links) rather than the centered search <dialog> — this is a small
   toolbar menu, not a page-level modal. */
.locale-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 60;
  list-style: none; margin: 0; padding: var(--space-8);
  display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--space-4);
  width: max-content; max-width: 232px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(-4px) scale(.98); pointer-events: none;
  transition: opacity var(--duration-micro) var(--ease-out-expo),
              transform var(--duration-micro) var(--ease-out-expo);
}
.locale-menu[aria-hidden="false"] { opacity: 1; transform: none; pointer-events: auto; }

.locale-option {
  display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 6px; padding: 5px;
  background: none; cursor: pointer;
  transition: background-color var(--duration-micro) var(--ease-out-expo),
              border-color var(--duration-micro) var(--ease-out-expo);
}
.locale-option:hover { background: var(--bg-subtle); }
/* Same accent treatment for both: the selected language (aria-checked)
   AND wherever keyboard focus currently is (:focus-visible, moving as
   you arrow through the grid) both get the accent border + tint. They're
   usually the same element right after opening (focus starts on the
   checked option) and simply overlap with no visual conflict when they
   diverge as you arrow away from it. */
.locale-option[aria-checked="true"],
.locale-option:focus-visible {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  outline: none;
}

/* Flags are multi-color art baked into the SVG itself, unlike every other
   icon in the sprite (.search-trigger-icon, .locale-trigger-icon, etc.
   are single-stroke currentColor shapes) — do not force
   fill:none/stroke:currentColor here, that would blank them out. */
.locale-flag {
  width: 22px; height: 15.5px; display: block; border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15);
}

/* Announces the switch to screen readers without a visible element —
   same pattern as a live region, not tied to any existing site.css class. */
.locale-announce {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (max-width: 900px) {
  .locale-menu { right: auto; left: 50%; transform: translate(-50%, -4px) scale(.98); }
  .locale-menu[aria-hidden="false"] { transform: translateX(-50%); }
}

@media print {
  .locale-switcher { display: none !important; }
}

/* ---------- Google Translate ---------- */
/* Loading/driving logic lives in locale.js; this is only the static
   resource hints (cheap even if translate is never engaged) and the
   chrome-hiding rules. */
#translate { display: none; }

[class^="VI"],
#google_translate_element,
.skiptranslate,
.goog-te-banner-frame.skiptranslate,
.goog-tooltip,
.goog-tooltip:hover {
  display: none !important;
}
.goog-text-highlight {
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
}
.google-src-text {
  background-color: transparent !important;
  text-decoration: none !important;
  z-index: 1;
}
/* Google's own translate bar pushes body down with an inline top offset
   on <html> — our custom menu replaces that bar entirely, so undo it. */
html.translated-ltr, html.translated-rtl { top: 0 !important; }
body { top: 0 !important; }
