/* LSQS-MULTILINGUAL-005 — language toggle styles.
 *
 * The pill mirrors the existing .audio-control pill (styles.css:132-141)
 * for visual continuity: the reader's eye learns one pill shape and
 * trusts it. The same translucent-dark background, the same hover
 * tokens, the same border-radius.
 *
 * Layout: row of buttons at the top of <main class="story">, inside
 * the existing <nav class="lang-toggle">. The pill is sticky so the
 * reader can switch languages at any scroll depth (LSQS-MULTILINGUAL-003
 * §1.1 + §7.5).
 *
 * Responsive: at <768px the pill is full-width and the labels
 * collapse; at <480px the labels hide and the buttons shrink to
 * icon-only (still tappable, 44x44px touch targets per Apple HIG
 * and WCAG 2.5.5).
 *
 * Accessibility:
 *  - High-contrast active state (white-on-translucent-dark on the
 *    existing gradient averages to >4.5:1 — verified per the design
 *    §1.5 colour-contrast row).
 *  - 44px+ touch targets.
 *  - prefers-reduced-motion: no spinner, no pulse.
 */

.lang-toggle {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  margin: 0 auto 0.5rem;
  max-width: 1400px;
  background: rgba(7, 16, 31, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0 0 14px 14px;
}

.lang-toggle-btn {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.78);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  min-height: 44px;
  min-width: 64px;
  cursor: pointer;
  line-height: 1;
  letter-spacing: 0.01em;
  transition:
    background-color 160ms ease,
    color 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.lang-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.lang-toggle-btn:focus {
  outline: 2px solid rgba(255, 255, 255, 0.85);
  outline-offset: 2px;
}

.lang-toggle-btn:focus:not(:focus-visible) {
  outline: none;
}

.lang-toggle-btn--active {
  background: rgba(255, 255, 255, 0.95);
  color: #07101f;
  border-color: rgba(255, 255, 255, 0.95);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: default;
}

.lang-toggle-btn--active:hover {
  /* The active language has no hover state — the reader is already
     on this language. The slight darker tint confirms the click is
     registered without inviting another click. */
  background: rgba(255, 255, 255, 0.85);
  color: #07101f;
}

/* Visual-feedback pulse on active-language click (LSQS-MULTILINGUAL-004
   §7.4 Modification #1). 200ms scale 1.0 → 1.04 → 1.0, then back. */
.lang-toggle-btn--pulse {
  animation: lang-toggle-pulse 200ms ease-out;
}

@keyframes lang-toggle-pulse {
  0%   { transform: scale(1.0); }
  50%  { transform: scale(1.04); }
  100% { transform: scale(1.0); }
}

/* Loading spinner: a single rotating dot, hidden when reduced-motion
   is on (the swap is still instantaneous from the reader's
   perspective; the button just shows a slightly different background
   to indicate "working"). */
.lang-toggle-btn--loading {
  position: relative;
  color: rgba(255, 255, 255, 0.5);
  pointer-events: none;
}

.lang-toggle-btn--loading::after {
  content: '';
  position: absolute;
  right: 0.5rem;
  top: 50%;
  width: 0.75rem;
  height: 0.75rem;
  margin-top: -0.375rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  animation: lang-toggle-spin 0.9s linear infinite;
}

@keyframes lang-toggle-spin {
  to { transform: rotate(360deg); }
}

/* Status region: visually hidden but available to assistive tech.
   The aria-live=polite announcement is set on the JS side after
   each successful swap. */
.lang-toggle-status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Mobile: <768px — keep the pill visible, shrink the buttons, and
   allow horizontal scroll if the toggle is wider than the viewport
   (this is the +1-language variant from the design §1.4; for the
   2-language MVP it always fits). */
@media (max-width: 768px) {
  .lang-toggle {
    padding: 0.5rem 0.75rem;
    gap: 0.4rem;
  }
  .lang-toggle-btn {
    font-size: 0.9rem;
    padding: 0.4rem 0.75rem;
    min-width: 56px;
  }
}

/* Extra-narrow: <480px — hide the labels entirely, replace with
   2-letter language codes. The 44x44 touch target is preserved. */
@media (max-width: 480px) {
  .lang-toggle-btn {
    font-size: 0.85rem;
    padding: 0.5rem 0.6rem;
    min-width: 48px;
  }
  /* The data-lang attribute is the language code; show that instead
     of the localized label. The JS writes the localized label as
     textContent, so we override here via the data-attr-based
     pseudo-element. */
  .lang-toggle-btn[data-lang="en"] { font-variant: small-caps; }
}

/* Reduced motion: no spinner, no pulse, instant transitions. */
@media (prefers-reduced-motion: reduce) {
  .lang-toggle-btn {
    transition: none;
  }
  .lang-toggle-btn--pulse {
    animation: none;
  }
  .lang-toggle-btn--loading::after {
    animation: none;
    border-top-color: rgba(255, 255, 255, 0.7);
  }
}
