@layer components {
  .search {
    --rows-margin: 0;

    .rows {
      inline-size: 100%;
      margin-inline: auto;
      max-inline-size: min(80ch, 100%);
      text-align: start;
    }

    mark {
      background-color: var(--color-highlight);
      border-radius: var(--radius-sm);
      color: var(--color-ink);
      padding: 0;
    }
  }

  /* Fizzy's .search scrolls inside the bar's modal. On the page nothing scrolls, and the overflow would cut the
     list's shadow at the sides. */
  .search-perma .search {
    overflow: visible;
  }

  /* The results page: the field across the sheet, then a reading-width column of results, each with its kind in a
     round mark, a quiet line of what and whose over its title, and the words it matched marked where they are. */
  .search-perma {
    --search-mark-size: 2.5rem;         /* 40px */
    --search-column: 100%;

    @media (min-width: 100ch) {
      --search-mark-size: 2.1rem;        /* 40px */
      --search-column: 41.25rem;         /* 784px */
    }

    /* The field across the sheet, 42 tall, with the lens at its start and the clear button inside its end. */
    .search__form {
      position: relative;
    }

    .search__icon {
      --icon-size: 1em;

      color: var(--color-ink-dark);
      inset-inline-start: 0.75em;
      pointer-events: none;
      position: absolute;
    }

    .search__input {
      --input-padding: 0 2.6em 0 2.4em;

      block-size: 2.625rem;               /* 42px */
      max-inline-size: none;

      @media (min-width: 100ch) {
        block-size: 2.21rem;              /* 42px */
      }
    }

    .search__reset {
      --btn-background: transparent;
      --btn-color: var(--color-ink-dark);
      --btn-size: 1.6em;

      inset-inline-end: 0.5em;
      position: absolute;
    }

    .search {
      padding-block: 0;
    }

    .search .rows {
      max-inline-size: var(--search-column);
      margin-inline: 0;
    }

    .search__blank-slate {
      margin: 0;
    }

    /* Nothing found is a grey box across the results column, in ink words. */
    .search__blank-slate--no-matches {
      background-color: var(--tint-ink-5);
      border: 0;
      color: var(--color-ink);
      inline-size: 100%;
      max-inline-size: var(--search-column);
      padding: 1em 1.5em;                 /* 16px 24px */

      > strong {
        font-weight: 700;
      }
    }

    .search .row {
      align-items: start;
      margin-block: 0.4em;
    }

    .inbox__link {
      align-items: start;
      gap: 0.75em;
      isolation: isolate;
      position: relative;

      /* The round mark the kind's icon sits on. */
      &::before {
        position: absolute;
        inset-block-start: 0;
        inset-inline-start: 0;
        z-index: -1;
        inline-size: var(--search-mark-size);
        block-size: var(--search-mark-size);
        border-radius: 50%;
        background-color: var(--color-meta-fill);
        content: "";
      }
    }

    .inbox__link > .icon {
      --icon-size: calc(var(--search-mark-size) * 0.45);

      margin: calc(var(--search-mark-size) * 0.275);
      color: var(--color-meta);
    }

    .row__body {
      display: flex;
      flex-direction: column;
      gap: 0.15em;
      min-inline-size: 0;
    }

    /* What it is and whose, over the title. */
    .row__meta:not(.search__excerpt) {
      order: -1;
    }

    .row__title {
      font-weight: 600;
    }

    /* The matched passage, on one line that fills the column. */
    .search__excerpt {
      color: var(--color-ink-dark);
      line-height: 1.4;
    }

    mark {
      padding-inline: 0.1em;
      font-weight: inherit;
    }

    /* A marked word the ellipsis would cut goes whole, instead of leaving a sliver of its fill at the line's end.
       As a block of its own its fill would take the line's full height: on a tighter line it covers the word alone. */
    .search__excerpt mark {
      display: inline-block;
      line-height: 1.2;
    }
  }

  /* Under the field the rail, then the results: 200 and 784 wide side by side, 25 apart, from a tablet up; on a phone
     the rail is a row of its own over them. */
  .search-layout {
    --search-rail: 12.5rem;               /* 200px */
    --search-rail-gap: 1.5625rem;         /* 25px */

    display: flex;
    flex-direction: column;
    gap: var(--block-space);
    margin-block-start: 1.25rem;          /* 20px */

    @media (min-width: 100ch) {
      --search-rail: 10.53rem;            /* 200px */
      --search-rail-gap: 1.32rem;         /* 25px */

      margin-block-start: 1.05rem;        /* 20px */
    }

    > turbo-frame {
      display: block;
      min-inline-size: 0;
    }
  }

  @container layout (inline-size >= 640px) {
    .search-layout:has(> .search-rail) {
      align-items: start;
      column-gap: var(--search-rail-gap);
      display: grid;
      grid-template-columns: var(--search-rail) minmax(0, var(--search-column));
    }
  }

  /* The order as two segments, then what narrows the results: a bold line over a menu for each, plain lines of 14px
     words with their icons, the chosen one in bold. */
  .search-rail {
    display: flex;
    flex-direction: column;
    font-size: var(--text-control);
    gap: 1.15em;
    min-inline-size: 0;

    .segments {
      align-self: start;
      flex-wrap: nowrap;
    }

    .segments__item {
      padding-inline: 0.7em;
    }
  }

  .search-rail__menus {
    align-items: start;
    display: flex;
    flex-direction: column;
    gap: 0.15em;
    min-inline-size: 0;

    .quick-filter {
      max-inline-size: 100%;
    }
  }

  .search-rail__title {
    font-size: 1em;
    font-weight: 700;
    margin: 0 0 0.35em;
    padding-inline: 0.5em;
  }

  .search-rail__menu:is(.btn) {
    --btn-background: transparent;
    --btn-border-size: 0;
    --btn-color: var(--color-ink);
    --btn-gap: 0.6em;
    --btn-hover-amount: 8%;
    --btn-padding: 0 0.5em;
    --icon-size: 1.1em;

    font-weight: 500;
    max-inline-size: 100%;
    min-block-size: 2.36em;               /* 33px */

    .icon {
      color: var(--color-meta);
    }

    .quick-filter:not(.quick-filter--with-default) & {
      font-weight: 700;
    }
  }

  /* Folded behind its button where the column is wide. */
  .search-rail__toggle {
    display: none;
  }

  /* On a phone the menus fold behind a full-width button with the filter's icon at its end, and open under it as
     the same lines. The button names them, so their heading goes. */
  @container layout (inline-size < 640px) {
    .search-rail__toggle:is(.btn) {
      --btn-border-color: var(--tint-ink-25);
      --btn-font-weight: 600;
      --btn-padding: 0 0.85em;

      display: flex;
      min-block-size: 2.5rem;             /* 40px */
      text-align: start;

      .icon {
        color: var(--color-meta);
      }
    }

    .search-rail:not(.search-rail--open) .search-rail__menus,
    .search-rail__title {
      display: none;
    }
  }
}
