/* Compact search box (pages without the translator) */

search {
  display: contents;
}

/* One bar: the language choice, a divider, the input and the button inside a single outlined field that lights up
   while anything in it has focus. Phones: the language choice is the bar's first row, the input and button below. From
   40rem: one row. */
.search-form {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  max-width: var(--width-search);
  padding: var(--space-1);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border-control);
  border-radius: var(--radius-lg);
  transition:
    border-color var(--duration-base),
    box-shadow var(--duration-base);
}

.search-form:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 var(--focus-ring-width) color-mix(in srgb, var(--color-accent) 25%, transparent);
}

/* The keyboard ring moves from the control to the whole bar (the controls have no box of their own). */
.search-form:has(input:focus-visible, select:focus-visible) {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

.search-form input,
.search-form select {
  min-width: 0;
  padding: var(--space-2) var(--space-3);
  font: inherit; /* 16px on phones: iOS zooms the page into any field with smaller text */
  color: inherit;
  background: transparent;
  border: 0;
  outline: none;
}

.search-form input {
  flex: 1;
}

.search-language {
  position: relative;
  display: flex;
  flex: 1 1 100%;
  margin-bottom: var(--space-1);
  border-bottom: var(--border-width) solid var(--color-border);
}

.search-language select {
  flex: 1;
  padding-right: var(--space-8);
  appearance: none;
  cursor: pointer;
}

/* The options are drawn by the browser; give them the page's colours rather than the transparent select's. */
.search-language option {
  color: var(--color-text);
  background: var(--color-surface);
}

/* The arrow: a small chevron in the text's muted colour. */
.search-language::after {
  content: '';
  position: absolute;
  top: 50%;
  right: var(--space-3);
  width: var(--space-2);
  height: var(--space-2);
  border-right: var(--border-width-strong) solid var(--color-text-muted);
  border-bottom: var(--border-width-strong) solid var(--color-text-muted);
  transform: translateY(-75%) rotate(45deg);
  pointer-events: none;
}

@media (min-width: 40rem) {
  .search-form {
    flex-wrap: nowrap;
  }

  .search-language {
    flex: none;
    max-width: 45%;
    margin: 0 var(--space-1) 0 0;
    border-bottom: 0;
    border-right: var(--border-width) solid var(--color-border);
  }

  .search-language select {
    font-size: var(--text-smaller);
    font-weight: var(--weight-medium);
  }
}

.search-form button {
  flex: none;
  padding: var(--space-2) var(--space-5);
  font: inherit;
  font-weight: var(--weight-semibold);
  color: var(--color-on-accent);
  background: var(--color-accent);
  border: 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--duration-base);
}

.search-form button:hover {
  background: color-mix(in srgb, var(--color-accent) 88%, var(--color-text));
}

.suggestions {
  position: absolute;
  top: calc(100% + var(--space-1));
  left: 0;
  right: 0;
  z-index: var(--z-dropdown);
  margin: 0;
  padding: var(--space-1) 0;
  list-style: none;
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

/* The list drops in when it opens (an animation runs again each time `hidden` comes off), its rows a moment apart. */
.suggestions:not([hidden]) {
  animation: suggestions-in var(--duration-base) var(--ease-out);
  transform-origin: top;
}

@keyframes suggestions-in {
  from {
    opacity: 0;
    translate: 0 calc(var(--space-1) * -1);
    scale: 1 0.96;
  }
}

.suggestions > li {
  animation: result-in var(--duration-enter) var(--ease-out) both;
}

.suggestions > li:nth-child(2) {
  animation-delay: calc(1 * var(--duration-stagger));
}
.suggestions > li:nth-child(3) {
  animation-delay: calc(2 * var(--duration-stagger));
}
.suggestions > li:nth-child(4) {
  animation-delay: calc(3 * var(--duration-stagger));
}
.suggestions > li:nth-child(5) {
  animation-delay: calc(4 * var(--duration-stagger));
}
.suggestions > li:nth-child(6) {
  animation-delay: calc(5 * var(--duration-stagger));
}
.suggestions > li:nth-child(7) {
  animation-delay: calc(6 * var(--duration-stagger));
}
.suggestions > li:nth-child(n + 8) {
  animation-delay: calc(7 * var(--duration-stagger));
}

.suggestions a {
  display: block;
  padding: var(--space-2) var(--space-3);
  color: var(--color-text);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggestions a:hover,
.suggestions a:focus {
  background: color-mix(in srgb, var(--color-accent) 8%, transparent);
}

/* Inside the list, so the ring doesn't spill over the neighbouring suggestions. */
.suggestions a:focus-visible {
  outline-offset: calc(var(--focus-ring-width) * -1);
}

.suggestions span {
  margin-left: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-smaller);
}

.suggestions .transliterated {
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border-width) solid var(--color-border);
}
