/* ============================================================
   The FAQ: a search field, the subjects beside the questions.

   Built on `.question` from custode.css, the accordion the homepage already
   uses, and on the painted dots the menu marks its current page with.
   ============================================================ */

/* Where a subject lands under the sticky header. Set once, on the page's own
   scroll padding: a scroll-margin as well would add to it. The header is 75 to
   98px tall depending on the width, so faq.js replaces these with the real
   numbers; these are what a page without the script gets. */
:root { --faq-top: 122px; --faq-offset: 122px; }
html:has(.faq) { scroll-padding-top: var(--faq-offset); }

.faq-head { padding-bottom: clamp(24px, 3vw, 40px); }
.faq-head .lede { max-width: 56ch; }

/* ---------- search ---------- */

.faq-search { position: relative; max-width: 420px; margin-top: clamp(24px, 3vw, 36px); }
.faq-search__icon {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
.faq-search .faq-search__input {
  font-size: 16px; line-height: 1.3;
  padding: 10px 64px 10px 30px; text-overflow: ellipsis;
  -webkit-appearance: none; appearance: none;
}
/* The whole sentence has to be read, so full strength: 4.5:1 on paper. */
.faq-search .faq-search__input::placeholder { color: var(--muted); opacity: 1; text-overflow: ellipsis; }
.faq-search__input::-webkit-search-cancel-button { display: none; }

.faq-search__clear {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  min-height: 44px; padding: 0 0 0 16px; background: none; border: 0; cursor: pointer;
  font: 500 11px/1 var(--text); letter-spacing: 2.2px; text-transform: uppercase;
  color: var(--terracotta-text);
}
.faq-search__clear:hover { color: var(--ink); }

/* Held open while empty, so the list does not jump as the first letter lands. */
.faq-status { min-height: 22px; margin-top: 12px; font-size: 13px; line-height: 22px; color: var(--muted); }

/* ---------- the two columns ---------- */

.faq-body { padding-top: clamp(16px, 2vw, 32px); }

.faq {
  display: grid; grid-template-columns: minmax(0, 228px) minmax(0, 1fr);
  gap: clamp(48px, 7vw, 104px); align-items: start;
}

.faq__index {
  position: sticky; top: var(--faq-top);
  max-height: calc(100dvh - var(--faq-top) - 24px); overflow-y: auto; scrollbar-width: none;
  /* Room inside the scroller for the focus ring, which it would otherwise cut. */
  padding: 6px; margin: -6px;
}
.faq__index::-webkit-scrollbar { display: none; }
.faq__index ul { list-style: none; margin: 0; padding: 0; }
.faq__index a {
  position: relative; display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
  padding: 9px 0 9px 26px; font-size: 15px; line-height: 1.35; color: var(--body);
  transition: color .18s ease;
}
/* The dot that comes up beside a menu item, here beside the subject being read. */
.faq__index a::before {
  content: ""; position: absolute; left: 0; top: 12px; width: 14px; height: 14px;
  background: url(/assets/img/paper/dot-ink.svg?v=31fb6070cd) center / contain no-repeat;
  transform: scale(0); transition: transform .18s ease;
}
.faq__index a[aria-current="true"] { color: var(--ink); }
.faq__index a[aria-current="true"]::before { transform: scale(1); }
@media (hover: hover) and (pointer: fine) {
  .faq__index a:hover { color: var(--ink); }
  .faq__index a:hover::before { transform: scale(.6); }
  .faq__index a[aria-current="true"]:hover::before { transform: scale(1); }
}
.faq__index a[aria-disabled="true"] { color: var(--muted); pointer-events: none; }
.faq__count { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- the questions ---------- */

.faq__group + .faq__group { margin-top: clamp(56px, 6vw, 88px); }
.faq__group > h2 {
  font-family: var(--display); font-weight: 300; font-size: clamp(25px, 2.4vw, 32px); line-height: 1.2;
  letter-spacing: -.3px; margin-bottom: 22px;
}

.faq .question > summary h3 {
  font: inherit; color: inherit; letter-spacing: 0; text-transform: none; margin: 0; text-wrap: pretty;
}
.faq .question:target > summary { color: var(--terracotta-text); }

.faq .question > p { padding: 0 0 12px; max-width: 62ch; font-size: 16px; line-height: 1.75; color: var(--body); }
.faq .question > p:last-child { padding-bottom: 28px; }
.faq .question a {
  color: var(--terracotta-text); border-bottom: 1px solid var(--rule-mid); transition: border-color .18s ease;
}
.faq .question a:hover { border-bottom-color: var(--terracotta); }

.faq-hit { background: var(--paper-deep); color: var(--ink); border-bottom: 1px solid var(--terracotta); }

.faq__empty { padding-top: 8px; }
.faq__empty .actions { margin-top: 24px; }
.faq__empty-line { font-family: var(--display); font-size: clamp(20px, 2vw, 24px); line-height: 1.4; color: var(--ink); max-width: 30ch; }

.faq-close { text-align: center; }
.faq-close .lede { margin: 18px auto 0; max-width: 52ch; }
.faq-close .actions { justify-content: center; margin-top: 32px; }

/* ---------- opening a question ----------

   Only where the browser can animate to a height it does not know yet.
   Elsewhere the answer simply appears. Not while searching: results opening
   and closing under every keystroke have to be immediate. */
@supports (interpolate-size: allow-keywords) {
  .faq { interpolate-size: allow-keywords; }
  .faq .question::details-content {
    height: 0; overflow: clip; overflow-clip-margin: 6px;
    transition: height .18s ease, content-visibility .18s ease allow-discrete;
  }
  .faq .question[open]::details-content { height: auto; }
  .faq.is-searching .question::details-content { transition: none; }
}

@media (prefers-reduced-motion: reduce) {
  .faq .question::details-content { transition: none; }
  .faq__index a, .faq__index a::before { transition: none; }
}

/* ---------- narrow: the subjects become a strip under the header ---------- */

@media (max-width: 860px) {
  :root { --faq-top: 98px; --faq-offset: 180px; }

  .faq { display: block; }

  .faq__index {
    z-index: 5; max-height: none;
    margin: 0 calc(-1 * var(--gutter)) 36px; padding: 10px var(--gutter);
    background: var(--paper); border-bottom: 1px solid var(--rule);
    overflow-x: auto; overscroll-behavior-x: contain;
  }
  .faq__index ul { display: flex; gap: 8px; width: max-content; }
  .faq__index a {
    align-items: center; gap: 8px; min-height: 44px; padding: 0 13px;
    border: 1px solid var(--rule-control); font-size: 13.5px; white-space: nowrap;
    transition: none; /* It changes as the page scrolls past: no fading along. */
  }
  .faq__index a::before { content: none; }
  .faq__index a[aria-current="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
  .faq__index a[aria-current="true"] .faq__count { color: inherit; }
  .faq__index a[aria-disabled="true"] { display: none; }
  .faq:has([data-faq-empty]:not([hidden])) .faq__index { display: none; }
}
