/* Styled popups keep the OS border and blue highlight out of the site palette. */
.custom-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  min-width: 0;
  min-height: 40px;
  margin: 0 0 14px;
  padding: 9px 11px;
  border: 1px solid #3b3d52;
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  font: 11px/1.5 var(--mono);
  text-align: left;
}
.custom-select-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.custom-select-chevron {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}
.custom-select-trigger[aria-expanded='true'] {
  border-color: var(--purple);
}
.custom-select-trigger[aria-expanded='true'] .custom-select-chevron {
  transform: translateY(2px) rotate(225deg);
}
.custom-select-trigger:not(:disabled):not([aria-disabled='true']):is(:hover, :active) {
  translate: none;
  scale: none;
}
.custom-select-trigger:focus-visible {
  outline: none;
  border-color: var(--cyan);
  box-shadow: inset 0 0 0 1px var(--cyan);
}
.custom-select-menu[hidden] {
  display: none;
}
.custom-select-menu {
  position: fixed;
  z-index: 60;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 5px;
  border: 1px solid #bd93f966;
  border-radius: 7px;
  background: var(--panel);
  color: var(--fg);
  box-shadow: 0 12px 28px #0005;
  scrollbar-width: thin;
  scrollbar-color: #bd93f966 transparent;
  font: 11px/1.5 var(--mono);
}
.custom-select-option {
  position: relative;
  padding: 9px 26px 9px 10px;
  border-radius: 4px;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.custom-select-option.is-active {
  background: #bd93f91f;
  color: var(--fg);
}
.custom-select-option[aria-selected='true'] {
  color: var(--purple);
}
.custom-select-option[aria-selected='true']::after {
  content: '◆';
  position: absolute;
  right: 9px;
  color: var(--green);
  font-size: 8px;
}
.custom-select-option[aria-disabled='true'] {
  opacity: 0.5;
  cursor: not-allowed;
}
@media (max-width: 720px) {
  .custom-select-trigger:not(.language-selector),
  .custom-select-menu {
    font-size: 12px;
  }
}
@media (pointer: coarse) {
  .custom-select-trigger:not(.language-selector) {
    min-height: 44px;
    font-size: 16px;
  }
  .custom-select-option {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

.custom-select-trigger.language-selector {
  width: 104px;
  display: grid;
  grid-template-columns: 4ch 22px minmax(7px, 1fr);
  justify-content: start;
  margin: 0;
  padding: 10px 8px;
  gap: 8px;
  font: 10px/1.5 var(--mono);
}
@media (max-width: 720px) {
  .custom-select-trigger.language-selector {
    width: 92px;
  }
}

/* Keep language artwork beside its label and the selected diamond at the edge. */
.custom-select-trigger.language-selector .custom-select-chevron {
  justify-self: end;
}
#language-selector-options {
  font: 10px/1.5 var(--mono);
}
.custom-select-option.language-option {
  display: grid;
  grid-template-columns: 4ch 22px;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 16px 6px 6px;
}
.language-option-label {
  white-space: nowrap;
}
@media (pointer: coarse) {
  .custom-select-option.language-option {
    min-height: 44px;
  }
}
.language-icon {
  translate: 2px 0;
  display: inline-flex;
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.language-icon svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.language-flag-strip {
  animation: language-cloth-wave 1.8s ease-in-out infinite;
  animation-delay: var(--wave-delay);
  animation-play-state: paused;
}
.language-earth-land {
  animation: language-earth-turn 7s linear infinite;
  animation-play-state: paused;
}
:is(.custom-select-menu:not([hidden]), .custom-select-trigger.language-selector)
  :is(.language-flag-strip, .language-earth-land) {
  animation-play-state: running;
}
@keyframes language-cloth-wave {
  0%,
  100% {
    transform: translateY(calc(-1 * var(--wave-height)));
  }
  50% {
    transform: translateY(var(--wave-height));
  }
}
@keyframes language-earth-turn {
  to {
    transform: translateX(-112px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .language-flag-strip,
  .language-earth-land {
    animation: none;
    transform: none;
  }
}

.language-selected-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}
.language-selected-icon .language-icon {
  width: 22px;
  flex-basis: 22px;
  height: 22px;
}
@media (max-width: 400px) {
  .custom-select-trigger.language-selector {
    width: 76px;
    padding-inline: 5px;
    gap: 6px;
    grid-template-columns: 4ch 20px minmax(7px, 1fr);
  }
  .language-selected-icon .language-icon {
    width: 20px;
    flex-basis: 20px;
    height: 20px;
  }
}

#language-selector-options .language-option[aria-selected='true']::after {
  right: 4px;
  font-size: 6px;
}
@media (max-width: 400px) {
  #language-selector-options {
    font-size: 9px;
  }
  .custom-select-option.language-option {
    grid-template-columns: 4ch 18px;
    gap: 4px;
    padding: 4px 14px 4px 4px;
  }
  .language-option .language-icon {
    width: 18px;
    height: 18px;
  }
}
