/**
 * Language Selector Styles
 * Floating language selector UI for internationalization
 */

/* The host is layout-neutral on phones, tablets, and non-lobby documents, so
   the established language and Feedback placement rules remain authoritative.
   Wide lobby layouts turn it into one fixed cluster below. */
.lobby-language-cluster {
  display: contents;
}

.language-selector {
  position: fixed;
  top: 0.75rem;
  /* Clear the responsive audio trigger at every scale. The old fixed 4rem
     offset collided with the trigger once its vmin size reached 60px on 4K. */
  right: calc(
    var(--mf-rail-edge)
    + var(--mf-rail-fullscreen-slot)
    + var(--mf-rail-btn)
    + 0.75rem
  );
  z-index: 9999;
  display: flex;
  align-items: center;
  height: 30px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.language-btn {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  margin: 0;
  padding: 0 0.85rem;
  height: 30px;
  border-radius: 999px;
  cursor: pointer;
  color: white;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: background 0.2s ease, border-color 0.2s ease,
    transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.language-btn:hover {
  background: rgba(30, 30, 50, 0.85);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.language-btn:active {
  transform: translateY(0);
}

.language-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: rgba(15, 15, 25, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  max-height: 70svh;
  overflow-y: auto;
  min-width: 220px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}

.language-selector.is-open .language-dropdown {
  display: block;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  animation: dropdownFadeIn 0.15s ease-out;
}

@keyframes dropdownFadeIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .language-selector.is-open .language-dropdown {
    animation: none;
  }
}

.language-region-header {
  padding: 0.5rem 1rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.4);
  font-weight: 600;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.02);
}

.language-option {
  padding: 0.65rem 1rem;
  min-height: 44px;
  box-sizing: border-box;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: rgba(255, 255, 255, 0.85);
  transition: background 0.15s ease, color 0.15s ease;
  font-size: 0.9rem;
  touch-action: manipulation;
}

.language-option:hover {
  background: rgba(100, 100, 255, 0.15);
  color: white;
}

.language-option:focus-visible {
  outline: 2px solid rgba(120, 210, 255, 0.95);
  outline-offset: -3px;
  background: rgba(100, 100, 255, 0.2);
  color: white;
}

.language-option.selected {
  background: rgba(100, 150, 255, 0.2);
  color: white;
}

.language-option.selected::after {
  content: '✓';
  margin-left: auto;
  color: rgba(100, 200, 255, 0.9);
  font-size: 0.85rem;
}

.language-flag {
  font-size: 1.1rem;
  /* Deliberately left at 1. Raising it to give an emoji more room shifted the
     language button's centre by ~1px, which desktop's Feedback/Language
     alignment oracle correctly caught in Japanese at 1366x768. The clipping
     that prompted it was reported in Moon Foundry, which uses a native
     <select> and not this element, so the fix belongs there (mobile.css) and
     not on a control shared by every surface. */
  line-height: 1;
}

.language-name {
  flex: 1;
}

/* Desktop utility chrome: Language is the first sibling and Feedback the
   second, so the least important control sits outermost, next to Mute.
   The same breakpoint is mirrored by UI.Lobby.syncUtilityPlacement;
   1366x768 belongs here, while squarer landscape tablets keep their existing
   in-flow Feedback control and enlarged 44px language target. */
@media (orientation: landscape) and (min-height: 561px) and (min-width: 1101px) and (min-aspect-ratio: 1601/1000),
  (orientation: landscape) and (min-height: 561px) and (min-width: 1367px) {
  .lobby-language-cluster {
    position: fixed;
    top: 0.75rem;
    right: calc(
      var(--mf-rail-edge)
      + var(--mf-rail-fullscreen-slot)
      + var(--mf-rail-btn)
      + 0.75rem
    );
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: 30px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  }

  .lobby-language-cluster .language-selector {
    position: relative;
    top: auto;
    right: auto;
    z-index: auto;
  }

  .lobby-language-cluster .feedback-link {
    position: static;
    right: auto;
    bottom: auto;
    z-index: auto;
    height: 30px;
    margin: 0;
    padding: 0 0.85rem;
    gap: 0.4rem;
    font-size: 0.8rem;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
}

/* Scrollbar styling for the dropdown */
.language-dropdown::-webkit-scrollbar {
  width: 6px;
}

.language-dropdown::-webkit-scrollbar-track {
  background: transparent;
}

.language-dropdown::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.language-dropdown::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* During game view, make it more subtle */
#game-view .language-selector {
  opacity: 0.6;
  transition: opacity 0.2s ease;
}

#game-view .language-selector:hover {
  opacity: 1;
}

/* Mobile responsiveness - hide on very small screens */
@media (max-width: 480px) {
  .language-selector {
    top: 0.5rem;
    right: 1.25rem;
  }

  .language-btn {
    padding: 0 0.8rem;
    height: 30px;
    line-height: 1;
    box-sizing: border-box;
    font-size: 0.8rem;
  }

  .language-dropdown {
    max-height: 60svh;
    min-width: 180px;
  }
}
