/* ---------------------------------------------------------------------------
   couch-find.css — search, the way a TV does it: the query large across the
   top, an on-screen keyboard on the left, results on the right.
--------------------------------------------------------------------------- */

.find {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgb(5 6 10 / 0.95);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  backdrop-filter: blur(24px) saturate(1.2);
}

.find[hidden] {
  display: none;
}

.find.is-entering {
  animation: find-in 0.3s var(--ease) both;
}

@keyframes find-in {
  from {
    opacity: 0;
    transform: scale(1.025);
  }
}

.find__sheet {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  padding: 0 var(--gutter);
}

.find__top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(14px, 2.2vw, 44px);
  padding-top: calc(var(--bar-h) * 0.3);
}

/* --- the query, large ------------------------------------------------- */

.find__query {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.35em;
  min-width: 0;
  padding: 0.12em 0;
  font-size: clamp(28px, min(4.4vw, 7.4vh), 100px);
  border-bottom: 2px solid var(--line);
  transition: border-color 0.2s;
}

.find__query:focus-within {
  border-color: #fff;
}

.find__glass {
  flex: none;
  width: 0.62em;
  height: 0.62em;
  color: var(--ink-3);
}

/* The field, and the echo of it drawn on top. */
.find__line {
  position: relative;
  display: flex;
  flex: 1;
  min-width: 0;
}

.find__field,
.find__echo {
  min-width: 0;
  flex: 1;
  font-size: 1em;
  line-height: 1.15;
  font-weight: 700;
  font-variation-settings: 'wdth' 76, 'wght' 760;
  letter-spacing: 0.005em;
}

.find__field {
  padding: 0;
  border: 0;
  background: none;
  color: transparent;
  caret-color: #fff;
  -webkit-appearance: none;
  appearance: none;
}

.find__field::-webkit-search-cancel-button {
  display: none;
}

.find__field::placeholder {
  color: transparent;
}

.find__field:focus {
  outline: none;
  color: var(--ink);
}

/* What is typed, drawn with a caret of its own, so the query shows typing
   from the on-screen keyboard as plainly as typing into the field. */
.find__echo {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  white-space: pre;
  overflow: hidden;
  pointer-events: none;
}

.find__field:focus + .find__echo span:not(.find__hint) {
  visibility: hidden;
}

.find__field:focus + .find__echo .find__caret {
  display: none;
}

.find__hint {
  color: var(--ink-3);
  order: 2;
}

.find__caret {
  order: 1;
  width: 0.06em;
  min-width: 2px;
  height: 0.9em;
  margin: 0 0.04em;
  background: #fff;
  animation: caret 1.1s steps(1) infinite;
}

.find__hint + .find__caret {
  margin-inline-start: 0;
}

@keyframes caret {
  50% {
    opacity: 0;
  }
}

/* How many, at the end of the field, where the eye already is. */
.find__count {
  flex: none;
  align-self: center;
  margin-inline-start: 0.6em;
  font-size: var(--type-m);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* --- the keyboard and the results, side by side ----------------------- */

.find__body {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: clamp(20px, 3.4vw, 70px);
  min-height: 0;
  padding-top: 4vh;
}

.osk {
  --key: min(4.5vw, 7.6vh);
  display: grid;
  grid-template-columns: repeat(6, var(--key));
  grid-auto-rows: var(--key);
  gap: calc(var(--key) * 0.14);
  align-content: start;
}

.osk__key {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35em;
  border-radius: calc(var(--key) * 0.18);
  background: var(--glass);
  font-size: calc(var(--key) * 0.36);
  font-weight: 600;
  font-variation-settings: 'wdth' 96, 'wght' 620;
  transition:
    transform var(--focus-ms) var(--ease),
    background-color 0.12s;
}

.osk__key[data-wide] {
  grid-column: span 2;
  font-size: calc(var(--key) * 0.28);
}

.osk__key svg {
  width: 1.4em;
  height: 1.4em;
}

.osk__key:hover {
  background: var(--glass-hi);
}

.osk__key:focus {
  outline: none;
  z-index: 1;
  background: #fff;
  color: var(--stage);
  transform: scale(1.1);
  box-shadow: 0 0.4em 1.6em -0.4em rgb(255 255 255 / 0.5);
}

.osk__pad {
  display: none;
  place-items: center;
  width: 1.4em;
  height: 1.4em;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  font-size: 0.78em;
  font-variation-settings: 'wdth' 100, 'wght' 800;
  opacity: 0.8;
}

[data-prompts='pad'] .osk__pad {
  display: inline-grid;
}

.find__results {
  min-height: 0;
  margin: calc(-1 * var(--track-pad));
  padding: var(--track-pad) var(--track-pad) 8vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.find__results::-webkit-scrollbar {
  display: none;
}

/* Three or four columns: a tile never narrower than a row tile, nor than a
   quarter of the room, so a wide screen gets bigger tiles, not more of them. */
.find__grid {
  display: grid;
  grid-template-columns: repeat(
    auto-fill,
    minmax(max(200px, calc(var(--tile-w) * 1.05), calc((100% - 3 * var(--tile-gap)) / 4)), 1fr)
  );
  gap: calc(var(--tile-gap) * 1.6) var(--tile-gap);
  align-content: start;
}

.find__grid .tile {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
}

.find__results:focus-within .tile:not(:focus) {
  filter: brightness(0.66) saturate(0.85);
}

.find__more {
  grid-column: 1 / -1;
  height: 1px;
}

/* --- before typing, and when nothing matches --------------------------- */

.find__empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.6vh;
  padding-top: 2vh;
}

.find__big {
  font-size: clamp(22px, min(3vw, 5vh), 60px);
  line-height: 1.05;
  font-weight: 700;
  font-variation-settings: 'wdth' 80, 'wght' 760;
  text-wrap: balance;
}

.find__small {
  max-width: 44ch;
  color: var(--ink-2);
}

.find__starters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6em;
  margin-top: 1vh;
}

.chip--button {
  height: 2.5em;
  padding: 0 1.1em;
  font-size: var(--type-m);
  transition:
    transform var(--focus-ms) var(--ease),
    background-color 0.12s;
}

.chip--button:hover {
  background: var(--glass-hi);
}

.chip--button:focus {
  outline: none;
  background: #fff;
  color: var(--stage);
  transform: scale(1.06);
}

.find__empty .btn {
  margin-top: 1vh;
}

/* --- a phone: its own keyboard instead of the grid ----------------------- */

@media (pointer: coarse), (max-width: 40rem) {
  .osk {
    display: none;
  }

  .find__body {
    grid-template-columns: minmax(0, 1fr);
    padding-top: 2.4vh;
  }

  .find__field {
    color: var(--ink);
  }

  .find__echo {
    display: none;
  }

  .find__field::placeholder {
    color: var(--ink-3);
  }
}

@media (max-width: 46rem), (max-aspect-ratio: 1/1) {
  .find__top {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .find__top .page__back span:not(.prompt) {
    display: none;
  }

  .find__views {
    display: none;
  }

  .find__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
