.cm-no-scroll {
  overflow: hidden;
}

.am-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--t-base) ease, visibility var(--t-base) ease;
}
.am-overlay.is-open {
  opacity: 1;
  visibility: visible;
}
.am-panel {
  width: min(1100px, 100%);
  max-height: min(86dvh, 820px);
  display: flex;
  flex-direction: column;
  background: linear-gradient(347deg, rgba(20, 10, 16, 0.96) 0%, rgba(60, 28, 38, 0.96) 100%);
  border: 1px solid rgba(var(--pink), 0.18);
  border-radius: 18px;
  overflow: hidden;
  color: #f0f0f0;
  transform: translateY(16px) scale(0.985);
  transition: transform var(--t-base) var(--ease-pop);
}
.am-overlay.is-open .am-panel {
  transform: none;
}
.am-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 26px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.am-title {
  font-weight: 400;
  font-size: clamp(20px, 2vw, 30px);
  /* keep a long name from shoving the close button off-panel */
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.am-close {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #f3f3f3;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background var(--t-base) ease;
}
.am-close:hover {
  background: rgba(255, 255, 255, 0.16);
}
.am-search {
  margin: 18px 26px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  height: 52px;
  border-radius: 14px;
  background: rgba(var(--pink), 0.12);
}
.am-search input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: none;
  color: #f0f0f0;
  font-family: inherit;
  font-size: 18px;
}
.am-search input::placeholder {
  color: rgba(240, 240, 240, 0.5);
}
.am-clear {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #f0f0f0;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background var(--t-base) ease;
}
.am-clear:hover {
  background: rgba(255, 255, 255, 0.22);
}
.am-clear[hidden] {
  display: none; /* beat the display:flex above */
}

.am-results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 26px 26px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px 16px;
  align-content: start;
  align-items: start;
}
.am-result {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid rgb(var(--rose));
  background: rgba(0, 0, 0, 0.4);
  cursor: pointer;
  /* padding-bottom 2:3 ratio, not aspect-ratio: on a grid item aspect-ratio
     collapses the row tracks and the cards overlap. */
  height: 0;
  padding-bottom: 150%;
  transition: transform var(--t-base) var(--ease-snap);
}
.am-result:hover {
  transform: translateY(-3px);
}
.am-result:focus-visible {
  outline: 2px solid rgb(var(--pink));
  outline-offset: 2px;
}
.am-result img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.am-result .am-result-title {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 16px 6px 6px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent);
  font-size: 12px;
  text-align: center;
  color: #fff;
}
/* "✓" badge, shown once the movie is in the list */
.am-result .am-add-flag {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(var(--pink), 0.9);
  color: #fff;
  font-size: 18px;
  line-height: 1;
}
.am-result.is-added .am-add-flag {
  display: flex;
}
.am-result.is-added::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 3px solid rgba(var(--pink), 0.9);
  border-radius: 4px;
  pointer-events: none;
}
.am-info {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--t-base) ease, background var(--t-base) ease;
}
.am-result:hover .am-info,
.am-result:focus-within .am-info,
.am-info:focus-visible {
  opacity: 1;
}
.am-info:hover {
  background: rgba(var(--pink), 0.9);
}
.am-hint {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 16px;
  color: var(--text-soft);
}

/* phones: shrink the min track so cards still land ~3 across */
@media (max-width: 640px) {
  .am-overlay {
    padding: 12px;
  }
  .am-panel {
    max-height: min(92dvh, 820px);
  }
  .am-header {
    padding: 18px 18px 14px;
  }
  .am-search {
    margin: 14px 18px 10px;
  }
  .am-results {
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    padding: 6px 18px 22px;
    gap: 12px 10px;
  }
}
/* touch devices never hover, keep the details button visible */
@media (hover: none) {
  .am-info {
    opacity: 0.92;
  }
}

@media (prefers-reduced-motion: reduce) {
  .am-overlay,
  .am-panel,
  .am-result {
    transition: none;
  }
}
