/* Shared language FAB — tree expands BELOW the icon */

.lux-lang-fab {
  --llf-size: 52px;
  --llf-gap: 8px;
  position: fixed;
  z-index: 9990;
  top: 50%;
  right: max(12px, env(safe-area-inset-right, 0px));
  transform: translateY(-50%);
  display: flex;
  flex-direction: column; /* icon first, languages grow downward like a tree */
  align-items: flex-end;
  gap: 0;
  font-family: Outfit, system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

[dir="rtl"] .lux-lang-fab {
  right: auto;
  left: max(12px, env(safe-area-inset-left, 0px));
  align-items: flex-start;
}

.lux-lang-fab-btn {
  position: relative;
  z-index: 3;
  width: var(--llf-size);
  height: var(--llf-size);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  background: linear-gradient(145deg, #4f46e5 0%, #7c3aed 100%);
  color: #fff;
  box-shadow:
    0 10px 28px rgba(79, 70, 229, 0.38),
    0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  padding: 0;
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-radius 0.22s ease;
}

.lux-lang-fab-btn:hover,
.lux-lang-fab.is-open .lux-lang-fab-btn {
  transform: scale(1.05);
  box-shadow:
    0 14px 34px rgba(79, 70, 229, 0.48),
    0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}

.lux-lang-fab.is-open .lux-lang-fab-btn {
  border-radius: 16px 16px 12px 12px;
}

.lux-lang-fab-btn:focus-visible {
  outline: 2px solid #a5b4fc;
  outline-offset: 3px;
}

.lux-lang-fab-btn svg,
.lux-lang-fab-btn i {
  font-size: 1.1rem;
  line-height: 1;
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

.lux-lang-fab-code {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  line-height: 1;
  opacity: 0.95;
}

/* Tree trunk line under the icon */
.lux-lang-fab-menu {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  margin-top: 10px;
  padding-top: 2px;
  min-width: 0;
  pointer-events: none;
}

.lux-lang-fab-menu::before {
  content: "";
  position: absolute;
  top: -10px;
  right: calc(var(--llf-size) / 2 - 1px);
  width: 2px;
  height: 10px;
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(129, 140, 248, 0.7), rgba(129, 140, 248, 0.15));
  opacity: 0;
  transform: scaleY(0);
  transform-origin: top center;
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

[dir="rtl"] .lux-lang-fab-menu::before {
  right: auto;
  left: calc(var(--llf-size) / 2 - 1px);
}

.lux-lang-fab.is-open .lux-lang-fab-menu::before {
  opacity: 1;
  transform: scaleY(1);
}

.lux-lang-fab-menu[hidden] {
  display: none !important;
}

.lux-lang-fab.is-open .lux-lang-fab-menu {
  pointer-events: auto;
}

/* Branch item — hangs from the tree */
.lux-lang-fab-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 152px;
  padding: 0.62rem 0.85rem 0.62rem 0.9rem;
  border-radius: 14px;
  text-decoration: none;
  color: #eef2ff;
  background: rgba(12, 12, 18, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-size: 0.88rem;
  font-weight: 550;
  opacity: 0;
  transform: translateY(-12px) scale(0.92);
  transform-origin: top right;
  transition:
    opacity 0.24s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.32s cubic-bezier(0.16, 1, 0.3, 1),
    background 0.15s ease,
    border-color 0.15s ease;
}

[dir="rtl"] .lux-lang-fab-item {
  transform-origin: top left;
}

/* Small branch connector from the trunk */
.lux-lang-fab-item::before {
  content: "";
  position: absolute;
  top: 50%;
  right: -10px;
  width: 10px;
  height: 2px;
  border-radius: 2px;
  background: rgba(129, 140, 248, 0.45);
  opacity: 0;
  transition: opacity 0.2s ease 0.05s;
}

[dir="rtl"] .lux-lang-fab-item::before {
  right: auto;
  left: -10px;
}

.lux-lang-fab.is-open .lux-lang-fab-item {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.lux-lang-fab.is-open .lux-lang-fab-item::before {
  opacity: 1;
}

/* Cascading tree reveal top → bottom */
.lux-lang-fab.is-open .lux-lang-fab-item:nth-child(1) { transition-delay: 0.03s; }
.lux-lang-fab.is-open .lux-lang-fab-item:nth-child(2) { transition-delay: 0.07s; }
.lux-lang-fab.is-open .lux-lang-fab-item:nth-child(3) { transition-delay: 0.11s; }
.lux-lang-fab.is-open .lux-lang-fab-item:nth-child(4) { transition-delay: 0.15s; }
.lux-lang-fab.is-open .lux-lang-fab-item:nth-child(5) { transition-delay: 0.19s; }
.lux-lang-fab.is-open .lux-lang-fab-item:nth-child(6) { transition-delay: 0.23s; }
.lux-lang-fab.is-open .lux-lang-fab-item:nth-child(7) { transition-delay: 0.27s; }

.lux-lang-fab-item:hover {
  background: rgba(79, 70, 229, 0.24);
  border-color: rgba(129, 140, 248, 0.4);
}

.lux-lang-fab-item.is-active {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.42), rgba(124, 58, 237, 0.3));
  border-color: rgba(165, 180, 252, 0.5);
  color: #fff;
}

.lux-lang-fab-item .llf-code {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #a5b4fc;
  min-width: 1.55rem;
}

.lux-lang-fab-item.is-active .llf-code {
  color: #e0e7ff;
}

.lux-lang-fab-item .llf-name {
  flex: 1;
  white-space: nowrap;
}

/* Mobile: bottom-right, still opens downward as tree */
@media (max-width: 720px) {
  .lux-lang-fab {
    top: auto;
    bottom: max(18px, env(safe-area-inset-bottom, 0px));
    transform: none;
    right: max(12px, env(safe-area-inset-right, 0px));
    /* On mobile open upward so list stays on screen */
    flex-direction: column-reverse;
  }

  [dir="rtl"] .lux-lang-fab {
    left: max(12px, env(safe-area-inset-left, 0px));
    right: auto;
  }

  .lux-lang-fab-menu {
    margin-top: 0;
    margin-bottom: 10px;
    padding-top: 0;
    padding-bottom: 2px;
  }

  .lux-lang-fab-menu::before {
    top: auto;
    bottom: -10px;
    transform-origin: bottom center;
  }

  .lux-lang-fab-item {
    transform: translateY(12px) scale(0.92);
    transform-origin: bottom right;
  }

  [dir="rtl"] .lux-lang-fab-item {
    transform-origin: bottom left;
  }

  .lux-lang-fab.is-open .lux-lang-fab-item {
    transform: translateY(0) scale(1);
  }

  .lux-lang-fab-item::before {
    display: none; /* cleaner on small screens */
  }

  .lux-lang-fab-btn {
    width: 50px;
    height: 50px;
    border-radius: 15px;
  }

  .lux-lang-fab-item {
    min-width: 142px;
  }
}
