@use "../variables" as *;
// Retro Dropdown
.retro-dropdown {
  position: relative;
  display: inline-block;

  &.open {
    .retro-dropdown-toggle {
      background: var(--retro-primary);
      color: var(--retro-primary-fg);
      border-color: var(--retro-primary-dark);
    }
  }
}
.retro-dropdown-toggle {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--retro-dropdown-bg);
  border: 2px solid var(--retro-border-dark);
  border-radius: var(--retro-border-radius);
  padding: 6px 16px;
  font-family: var(--retro-font);
  font-size: var(--retro-font-size-lg);
  color: var(--retro-dropdown-text);
  box-shadow: 1px 1px 0 var(--retro-border-light);
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  min-width: 120px;

  &:hover {
    background: var(--retro-gray-100);
  }

  &:active {
    box-shadow: none;
    transform: translate(1px, 1px);
  }
}
.retro-dropdown-arrow {
  margin-inline-start: 8px;
  font-size: var(--retro-font-size);
  transition: transform 0.2s ease;

  .open & {
    transform: rotate(180deg);
  }
}
.retro-dropdown-menu {
  position: absolute;
  inset-inline-start: 0;
  min-width: 100%;
  // A menu must never widen the page. Its items size to their longest label,
  // and on a narrow viewport — or in RTL, where the menu opens toward the left
  // edge — that pushed the document 35px past the viewport and gave every page
  // a horizontal scrollbar. Capped here, the overflow happens inside the menu,
  // which is where it belongs.
  max-width: calc(100vw - var(--retro-spacing-lg));
  overflow-x: auto;
  background: var(--retro-dropdown-bg);
  border: 2px solid var(--retro-border-dark);
  border-radius: var(--retro-border-radius);
  box-shadow: 2px 2px 0 var(--retro-border-light);
  z-index: 1000;
  margin-top: 2px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  // Deliberately NOT `transition: all`. visibility is a discrete property, so
  // `all` transitions it -- it flips at 50% of the duration, leaving the menu
  // `hidden` for the first 100ms after .open is set. Anything focused in that
  // window silently fails, which broke keyboard navigation into the menu.
  transition: opacity 0.2s ease, transform 0.2s ease;

  .retro-dropdown.open > & {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
}

/// A closed menu takes no space at all.
///
/// `visibility: hidden` hides it but keeps its box, and an absolutely
/// positioned box still counts toward the document's scrollable overflow. A
/// menu is as wide as its longest item, so on a narrow screen — or in RTL,
/// where it opens toward the other edge — the page grew a horizontal scrollbar
/// for a menu nobody could see. Collapsed to nothing until it opens, it cannot.
.retro-dropdown:not(.open) > .retro-dropdown-menu {
  width: 0;
  min-width: 0;
  height: 0;
  overflow: hidden;
}
.retro-dropdown-item {
  display: block;
  padding: 8px 16px;
  color: var(--retro-dropdown-text);
  text-decoration: none;
  font-family: var(--retro-font);
  font-size: var(--retro-font-size-lg);
  background: var(--retro-dropdown-bg);
  border-bottom: 1px solid var(--retro-border-light);
  // Explicit property list, not `all`. visibility is discrete AND inherited:
  // with `all`, an item inside a menu that flips visible transitions its own
  // inherited visibility, staying hidden for half the duration. Anything
  // focused in that window silently fails, which broke keyboard entry.
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  white-space: nowrap;
  cursor: pointer;

  &:last-child {
    border-bottom: none;
  }

  &:hover {
    background: var(--retro-primary);
    color: var(--retro-primary-fg);
  }

  &:active {
    background: var(--retro-primary-dark);
  }
} 