/* =========================================================
   search.css: the search box's shortcut hint and dropdown label
   (js/search.js). Separate file so search work doesn't collide with
   edits to components.css.
   ========================================================= */

/* ⌘K / Ctrl K, desktop only. Hidden while typing (the × takes its
   place) and while the box is focused (you're already there). */
.search-kbd {
  flex-shrink: 0;

  display: inline-flex;

  gap: 3px;

  opacity: 1;

  transition: opacity var(--dur-fast) ease;
}

.search-kbd[hidden],
.search:focus-within .search-kbd,
.clear-search.is-visible ~ .search-kbd,
.search:has(.clear-search.is-visible) .search-kbd {
  display: none;
}

.search-kbd kbd {
  min-width: 20px;

  padding: 1px 6px;

  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;

  background: var(--surface);
  color: var(--text-muted);

  font: inherit;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
}

.suggest-label {
  padding: 8px 10px 4px;

  color: var(--text-muted);

  font-size: var(--fs-label);
  font-weight: var(--fw-label);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
}

/* ---------- Suggestions: open/close motion ----------
   Closed: slightly up and smaller, transparent. Opening grows down
   from the box (transform-origin top) with a decelerating curve;
   closing is quicker and accelerates away. */
.search-suggest {
  transform-origin: top center;

  opacity: 0;
  transform: translateY(-6px) scale(0.97);

  animation: none;

  transition:
    opacity 150ms cubic-bezier(0.4, 0, 1, 1),
    transform 150ms cubic-bezier(0.4, 0, 1, 1);
}

.search-suggest.is-open {
  opacity: 1;
  transform: none;

  transition:
    opacity 220ms var(--ease-out),
    transform 220ms var(--ease-out);
}

/* Rows cascade in on open only; later updates while typing swap in
   place, so the list doesn't keep re-animating under your fingers. */
.search-suggest.is-entering .suggest-row {
  animation: suggest-row-in 240ms var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 22ms + 40ms);
}

@keyframes suggest-row-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

.suggest-row {
  transition: background var(--dur-fast) ease;
}

@media (prefers-reduced-motion: reduce) {
  .search-suggest,
  .search-suggest.is-open {
    transform: none;
    transition: opacity 120ms linear;
  }

  .search-suggest.is-entering .suggest-row {
    animation: none;
  }
}

/* ---------- Order inside the box ----------
   text · ⌘K (idle) or × (typing) · divider · mic, the arrangement
   Google and YouTube use: clearing belongs to the text, the mic is a
   separate way in, so it sits apart at the edge. */
.search input {
  order: 0;
}

.search-kbd,
.clear-search {
  order: 1;
}

.voice-search {
  order: 2;

  position: relative;

  margin-left: 2px;
}

.voice-search::before {
  content: "";

  position: absolute;
  left: -7px;
  top: 8px;
  bottom: 8px;

  width: 1px;

  background: var(--border-strong);
}

.voice-search:hover {
  background: var(--surface);
}

/* Room for the trailing controls without crowding the text. */
.search {
  gap: 8px;
  padding-right: 6px;
}

/* ---------- Placement fixes ----------
   The hidden × used to keep its 32px slot, leaving a gap between ⌘K
   and the mic. Now the × takes no space until there's text, and ⌘K
   (idle) / Esc (active) sit right against the divider. */
.clear-search:not(.is-visible) {
  width: 0;
  margin-left: -8px; /* cancel the flex gap it would otherwise leave */
}

.clear-search {
  transition:
    opacity var(--dur-fast) ease,
    transform var(--dur-fast) ease,
    width var(--dur-fast) ease,
    margin var(--dur-fast) ease,
    visibility 0s linear var(--dur-fast),
    background 0.15s ease,
    color 0.15s ease;
}

/* The hint stays visible while active, switching to "Esc"; it only
   gives way to the × once there's text. */
.search:focus-within .search-kbd {
  display: inline-flex;
}

.search-kbd .kbd-close,
.search:focus-within .search-kbd .kbd-open {
  display: none;
}

.search:focus-within .search-kbd .kbd-close {
  display: inline-block;
}

.search:has(.clear-search.is-visible) .search-kbd {
  display: none;
}

.search-kbd {
  margin-right: 6px;
}

.search-kbd kbd {
  padding: 1px 7px;

  letter-spacing: 0.02em;
}

/* ---------- Deactivation ----------
   Activating eases in (220ms); deactivating is quicker (150ms) and
   accelerates away, in step with the dropdown closing. */
.search {
  transition:
    border-color 150ms cubic-bezier(0.4, 0, 1, 1),
    background 150ms cubic-bezier(0.4, 0, 1, 1),
    box-shadow 150ms cubic-bezier(0.4, 0, 1, 1);
}

.search:focus-within {
  transition:
    border-color 220ms var(--ease-out),
    background 220ms var(--ease-out),
    box-shadow 220ms var(--ease-out);
}

/* ---------- AI picks (js/search-ai.js) ---------- */
.ai-picks {
  padding: var(--space-4);

  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);

  background:
    radial-gradient(120% 140% at 0% 0%, var(--pink-light), transparent 55%),
    var(--surface);

  animation: view-enter var(--dur-slow) var(--ease-out);
}

.ai-picks.is-quiet {
  padding: var(--space-3) var(--space-4);

  background: var(--surface);
}

.ai-picks-head {
  display: flex;
  align-items: center;

  gap: var(--space-3);
}

.ai-picks-badge {
  width: 36px;
  height: 36px;

  flex-shrink: 0;

  display: grid;
  place-items: center;

  border-radius: var(--radius-md);

  background: var(--pink-fill);
  color: #fff;
}

.ai-picks-badge svg {
  width: 18px;
  height: 18px;
}

.ai-picks.is-working .ai-picks-badge {
  animation: ai-pulse 1.4s ease-in-out infinite;
}

.ai-picks-heading {
  flex: 1;

  min-width: 0;
}

.ai-picks-title {
  margin: 0;

  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;

  font-size: var(--fs-title);
  font-weight: 800;
}

.ai-picks-status {
  margin: 2px 0 0;

  color: var(--text-muted);

  font-size: var(--fs-body-sm);
}

/* Three dots that keep moving while work is in progress */
.ai-picks.is-working .ai-picks-dots::after {
  content: "";

  display: inline-block;

  width: 1.2em;

  animation: ai-dots 1.2s steps(4, end) infinite;
}

@keyframes ai-dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}

.ai-picks-actions {
  display: flex;

  gap: var(--space-2);
}

.ai-picks-actions[hidden] {
  display: none;
}

.ai-picks-play,
.ai-picks-save {
  display: inline-flex;
  align-items: center;

  gap: 6px;
  padding: 8px 16px;

  border: none;
  border-radius: var(--radius-pill);

  font: inherit;
  font-size: var(--fs-body-sm);
  font-weight: 700;

  cursor: pointer;
}

.ai-picks-play {
  background: var(--pink-fill);
  color: #fff;
}

.ai-picks-play svg {
  width: 14px;
  height: 14px;
}

.ai-picks-save {
  border: 1px solid var(--border-strong);

  background: transparent;
  color: var(--text);
}

.ai-picks-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));

  gap: 2px var(--space-3);
  margin-top: var(--space-3);
}

.ai-picks-list:empty {
  display: none;
}

.ai-pick {
  min-width: 0;

  display: flex;
  align-items: center;

  gap: var(--space-3);
  padding: 6px;

  border-radius: var(--radius-md);

  cursor: pointer;

  animation: suggest-row-in 260ms var(--ease-out) both;
}

.ai-pick:hover,
.ai-pick:focus-visible {
  background: var(--surface-alt);
}

.ai-pick img,
.ai-pick .sr-art-fallback,
.ai-pick-skeleton .skeleton:first-child {
  width: 40px;
  height: 40px;

  flex-shrink: 0;

  border-radius: var(--radius-sm);

  object-fit: cover;
}

.ai-pick-skeleton {
  cursor: default;
}

.ai-pick-skeleton .skeleton-line {
  width: 60%;
}

.ai-pick-text {
  flex: 1;

  min-width: 0;

  display: flex;
  flex-direction: column;
}

.ai-pick-title,
.ai-pick-artist {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.ai-pick-title {
  font-size: var(--fs-body);
  font-weight: 600;
}

.ai-pick-artist,
.ai-pick-time {
  color: var(--text-muted);

  font-size: var(--fs-body-sm);
}

@media (max-width: 600px) {
  .ai-picks-head {
    flex-wrap: wrap;
  }

  .ai-picks-actions {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-picks,
  .ai-pick,
  .ai-picks.is-working .ai-picks-badge {
    animation: none;
  }
}

/* ---------- × : as light as the mic ----------
   It sat on a solid disc (white on Day), heavier than anything else
   in the box. Now a plain icon in the muted colour, like the mic, with
   a soft circle only on hover. */
.clear-search {
  background: transparent;
  color: var(--text-muted);
}

.clear-search svg {
  width: 14px;
  height: 14px;
}

.clear-search:hover {
  background: var(--surface-alt);
  color: var(--text);
}

/* ---------- Mic: listening states (js/search.js) ---------- */
.voice-search {
  overflow: visible;

  --level: 0;
}

.voice-icon {
  position: relative;
  z-index: 1;

  display: grid;
  place-items: center;

  transition:
    opacity var(--dur-fast) ease,
    transform var(--dur-fast) ease,
    color var(--dur-fast) ease;
}

.voice-icon svg {
  width: 16px;
  height: 16px;
}

.voice-icon-cancel {
  position: absolute;
  inset: 0;

  opacity: 0;
  transform: scale(0.6);
}

/* Water: clipped to the circle, rising with --level (0 to 1). */
.voice-fill {
  position: absolute;
  inset: 0;

  overflow: hidden;

  border-radius: 50%;

  pointer-events: none;
}

.voice-water {
  position: absolute;
  left: -50%;
  right: -50%;
  bottom: 0;

  height: calc(var(--level) * 100%);

  background: var(--pink-fill);

  transition: height 90ms linear;
}

/* A gentle wave on the water's surface */
.voice-water::before {
  content: "";

  position: absolute;
  left: 0;
  right: 0;
  top: -5px;

  height: 10px;

  background: radial-gradient(10px 6px at 10px 6px, var(--pink-fill) 98%, transparent) 0 0 / 20px 10px repeat-x;

  animation: voice-wave 0.9s linear infinite;
}

@keyframes voice-wave {
  to {
    transform: translateX(20px);
  }
}

/* Listening, silent: an arc circles the button. */
.voice-search.is-listening {
  background: var(--pink-soft);
  color: var(--pink);

  animation: none;
}

.voice-search.is-listening::after {
  content: "";

  position: absolute;
  inset: -3px;

  border-radius: 50%;

  background: conic-gradient(from 0deg, transparent 0 55%, var(--pink) 85%, transparent 100%);

  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px));

  animation: voice-orbit 1s linear infinite;
}

@keyframes voice-orbit {
  to {
    transform: rotate(1turn);
  }
}

/* Speaking: the icon turns white over the water. */
.voice-search.is-listening.is-speaking .voice-icon-mic {
  color: #fff;
}

/* Hover while listening (and always on touch screens): mic → ×. */
.voice-search.is-listening:hover .voice-icon-mic,
.voice-search.is-listening:focus-visible .voice-icon-mic {
  opacity: 0;
  transform: scale(0.6);
}

.voice-search.is-listening:hover .voice-icon-cancel,
.voice-search.is-listening:focus-visible .voice-icon-cancel {
  opacity: 1;
  transform: none;
}

.voice-search.is-listening:hover .voice-water {
  opacity: 0.35;
}

@media (hover: none) {
  .voice-search.is-listening .voice-icon-mic {
    opacity: 0;
  }

  .voice-search.is-listening .voice-icon-cancel {
    opacity: 1;
    transform: none;
    color: #fff;
  }
}

@media (prefers-reduced-motion: reduce) {
  .voice-search.is-listening::after,
  .voice-water::before {
    animation: none;
  }

  .voice-water {
    transition: none;
  }
}

/* Water only exists while listening, and its wave only once there's
   sound (it showed as a blob under the idle mic). */
.voice-fill {
  display: none;
}

.voice-search.is-listening .voice-fill {
  display: block;
}

.voice-water::before {
  opacity: 0;

  transition: opacity var(--dur-fast) ease;
}

.voice-search.is-speaking .voice-water::before {
  opacity: 1;
}

/* Under the waterline the mic turns white: a white copy of the icon,
   clipped to the water's height, sits over the pink one, so the icon
   stays readable at every level. */
.voice-icon-mic-wet {
  position: absolute;
  inset: 0;

  display: none;

  color: #fff;

  clip-path: inset(calc((1 - var(--level)) * 100%) 0 0 0);

  transition: clip-path 90ms linear, opacity var(--dur-fast) ease;
}

.voice-search.is-listening .voice-icon-mic-wet {
  display: grid;
}

.voice-search.is-listening.is-speaking .voice-icon-mic {
  color: var(--pink);
}

.voice-search.is-listening:hover .voice-icon-mic-wet,
.voice-search.is-listening:focus-visible .voice-icon-mic-wet {
  opacity: 0;
}

@media (hover: none) {
  .voice-search.is-listening .voice-icon-mic-wet {
    opacity: 0;
  }
}

/* ---- Saved ----
   After "Save as playlist": a pink outline and a check that draws
   itself in (about 400ms), with one soft pulse on the button. It then
   stays "✓ Saved" and opens the playlist on click (js/search-ai.js). */
.ai-picks-save.is-saved {
  border-color: var(--pink);

  color: var(--pink);
}

.ai-picks-save.is-saved:hover {
  background: var(--pink-soft);
}

.ai-picks-check {
  width: 14px;
  height: 14px;

  stroke-dasharray: 24;
  stroke-dashoffset: 0;
}

.ai-picks-save.just-saved {
  animation: ai-saved-pulse 500ms var(--ease-out);
}

.ai-picks-save.just-saved .ai-picks-check {
  animation: ai-saved-draw 400ms var(--ease-out) 80ms both;
}

@keyframes ai-saved-draw {
  from {
    stroke-dashoffset: 24;
  }
}

@keyframes ai-saved-pulse {
  0% {
    box-shadow: 0 0 0 0 var(--pink-light);
    transform: scale(1);
  }

  35% {
    transform: scale(1.06);
  }

  100% {
    box-shadow: 0 0 0 10px transparent;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-picks-save.just-saved,
  .ai-picks-save.just-saved .ai-picks-check {
    animation: none;
  }
}

/* =========================================================
   "What's this song?" on the Search page (js/search-home.js).
   The dialog it opens is styled in css/identify.css, loaded with it.
   ========================================================= */

.identify-entry {
  display: flex;
  align-items: center;
  gap: var(--space-3);

  width: min(420px, 100%);
  padding: var(--space-3) var(--space-4);

  border: 1px solid var(--border);
  border-radius: var(--radius-md);

  background: var(--surface);
  color: var(--text);

  text-align: left;

  cursor: pointer;

  transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out);
}

.identify-entry[hidden] {
  display: none;
}

.identify-entry:hover {
  border-color: var(--border-strong);

  background: var(--surface-alt);
}

.identify-entry:focus-visible {
  outline: 2px solid var(--pink);
  outline-offset: 2px;
}

.identify-entry-icon {
  display: grid;
  place-items: center;
  flex: none;

  width: 40px;
  height: 40px;

  border-radius: var(--radius-pill);

  background: var(--pink-light);
  color: var(--pink);
}

.identify-entry-icon svg {
  width: 20px;
  height: 20px;
}

.identify-entry-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.identify-entry-text strong {
  font-size: var(--fs-body-lg);
}

.identify-entry-text span {
  color: var(--text-muted);

  font-size: var(--fs-body-sm);
}

/* "What's this song?" and "Find the song in this Reel" rows in the
   dropdown (js/search.js): set apart from recents by a hairline, with
   the pink identify icon so they read as a different action. */
.suggest-row-identify {
  margin-top: 4px;
}

.suggest-label + .suggest-row-identify,
.suggest-row-identify:first-child {
  margin-top: 0;
}

.suggest-row:not(.suggest-row-identify) + .suggest-row-identify {
  position: relative;

  margin-top: 9px;
}

.suggest-row:not(.suggest-row-identify) + .suggest-row-identify::before {
  content: "";

  position: absolute;
  top: -5px;
  left: 10px;
  right: 10px;

  height: 1px;

  background: var(--border);
}

.suggest-art-identify {
  background: var(--pink-light);
  color: var(--pink);
}
