/* The FAQ that follows the computer section: the page's light ground, hairlines and columns, graphite
   ink, and the theme's accent, never blue, purple or orange. Everything here is scoped to #faq. */

@scope (#faq) {
  /* The page's tokens under the names this section was measured with. An open answer lifts into the
     white card the computer section uses for its current beat. */
  :scope {
    --bg: var(--ground);
    --body: var(--ink-2);
    --muted: var(--ink-soft);
    --line: rgb(23 24 27 / 0.1);
    --pill: var(--accent);
    --lift: 0 1px 2px rgba(23, 24, 27, 0.05), 0 8px 24px -12px rgba(23, 24, 27, 0.18), inset 0 0 0 1px var(--hair);
    /* faq.js replaces both with the answers' spring (faq-model.js ANSWER_SPRING), so every part of a row moves on one curve. */
    --spring: var(--ease-out);
    --spring-duration: 450ms;
    font-size: 1.0625rem;
    line-height: 1.55;
  }

  code {
    padding: 1px 5px;
    border-radius: 5px;
    background: var(--accent-soft);
    color: var(--ink);
    font: 500 0.875em/1 ui-monospace, 'SF Mono', Menlo, monospace;
  }

  strong {
    font-weight: 600;
    color: var(--ink);
  }

  /* ---------- the section ---------- */

  :scope {
    display: grid;
    grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
    align-items: start;
    gap: clamp(40px, 7vw, 128px);
    max-width: 1440px;
    margin: 0 auto;
    padding: clamp(40px, 7vw, 104px) clamp(20px, 4vw, 56px) clamp(72px, 10vw, 144px);
  }

  .intro {
    position: sticky;
    top: calc(var(--bar-h) + 40px);
  }

  .faq-orb {
    --orb-diameter: 64px;
  }

  h2 {
    margin: 24px 0 0;
    font-size: clamp(2.25rem, 3.3vw, 3.25rem);
    font-weight: 520;
    line-height: 1.03;
    letter-spacing: -0.035em;
    text-wrap: balance;
  }

  .lead {
    max-width: 34ch;
    margin: 18px 0 0;
    color: var(--body);
    text-wrap: pretty;
  }

  fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }

  /* Radio inputs stay real (arrow keys, one tab stop, the right announcements) and draw as pills. */
  .topics input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
  }

  .topics label:has(input:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .topics {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 32px;
  }

  .topics[hidden] {
    display: none;
  }

  .topics label {
    display: inline-flex;
    align-items: baseline;
    gap: 7px;
    padding: 7px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--body);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.35;
    cursor: pointer;
    user-select: none;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 140ms var(--ease-out);
  }

  .topics label:active {
    transform: scale(0.97);
  }

  .topics .count {
    color: var(--muted);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
    transition: color 160ms ease;
  }

  .topics label:has(input:checked) {
    border-color: var(--pill);
    background: var(--pill);
    color: #fff;
  }

  .topics label:has(input:checked) .count {
    color: rgba(255, 255, 255, 0.72);
  }

  .rule {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 28px 0 0;
    color: var(--muted);
    font-size: 0.875rem;
  }

  .rule-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    transition: background-color 320ms ease;
  }

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

  .questions {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .questions > li {
    position: relative;
  }

  /* Hairlines between closed rows (a filtered list starts clean); they step aside for an open card so it floats on the ground. */
  .questions > li:not([hidden]) ~ li::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20px;
    right: 20px;
    height: 1px;
    background: var(--line);
    transition: opacity 200ms ease;
  }

  .questions > li:has(> details[open]:not(.closing))::before,
  .questions > li:has(> details[open]:not(.closing)) + li::before {
    opacity: 0;
  }

  details {
    border-radius: 18px;
    transition: background-color var(--spring-duration) var(--spring), box-shadow var(--spring-duration) var(--spring);
  }

  details[open]:not(.closing) {
    background: var(--surface);
    box-shadow: var(--lift);
  }

  summary {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 20px 20px;
    border-radius: 18px;
    list-style: none;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 160ms ease, transform 140ms var(--ease-out);
  }

  summary::-webkit-details-marker {
    display: none;
  }

  summary:active {
    transform: scale(0.992);
  }

  summary:focus-visible {
    outline-offset: -2px;
  }

  .q {
    flex: 1;
    font-size: 1.0625rem;
    font-weight: 560;
    line-height: 1.35;
    letter-spacing: -0.012em;
    text-wrap: pretty;
  }

  .tag {
    flex: none;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-ink);
    font-size: 0.75rem;
    font-weight: 560;
    line-height: 1.3;
    transition: background-color 320ms ease, color 320ms ease;
  }

  /* A plus whose upright bar turns flat: the row says it will open, then that it will close. */
  .sign {
    position: relative;
    flex: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1px var(--line);
    transition: background-color var(--spring-duration) var(--spring), box-shadow var(--spring-duration) var(--spring);
  }

  .sign i {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 11px;
    height: 1.6px;
    margin: -0.8px 0 0 -5.5px;
    border-radius: 1px;
    background: var(--ink);
    transition: transform var(--spring-duration) var(--spring), background-color var(--spring-duration) var(--spring);
  }

  .sign i + i {
    transform: rotate(90deg);
  }

  details[open]:not(.closing) .sign {
    background: var(--pill);
    box-shadow: inset 0 0 0 1px var(--pill);
  }

  details[open]:not(.closing) .sign i {
    background: #fff;
  }

  details[open]:not(.closing) .sign i + i {
    transform: rotate(0deg);
  }

  .answer {
    overflow: hidden;
  }

  .answer-inner {
    padding: 0 20px 24px;
  }

  .answer p {
    max-width: 62ch;
    margin: 0;
    color: var(--body);
    font-size: 1rem;
    line-height: 1.62;
    text-wrap: pretty;
  }

  @media (hover: hover) and (pointer: fine) {
    details:not([open]) summary:hover,
    details.closing summary:hover {
      background: var(--hover);
    }

    details:not([open]) summary:hover .sign,
    details.closing summary:hover .sign {
      box-shadow: inset 0 0 0 1px rgba(23, 24, 27, 0.18);
    }

    .topics label:not(:has(input:checked)):hover {
      border-color: rgba(23, 24, 27, 0.2);
      color: var(--ink);
    }

  }

  /* ---------- narrow windows: one column, the intro scrolls away ---------- */

  @media (max-width: 860px) {
    :scope {
      grid-template-columns: minmax(0, 1fr);
      gap: 32px;
    }

    .intro {
      position: static;
    }

    .faq-orb {
      --orb-diameter: 52px;
    }

    h2 {
      margin-top: 22px;
    }

    .topics {
      margin-top: 24px;
    }

    .rule {
      margin-top: 20px;
    }

    .questions {
      margin: 0 -12px;
    }

    .questions > li:not([hidden]) ~ li::before {
      left: 16px;
      right: 16px;
    }

    summary {
      padding: 18px 16px;
      gap: 12px;
    }

    .answer-inner {
      padding: 0 16px 20px;
    }
  }

  @media (max-width: 420px) {
    .q {
      font-size: 1rem;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .sign i,
    summary,
    .topics label {
      transition-property: background-color, color, border-color, box-shadow;
    }

    summary:active,
    .topics label:active {
      transform: none;
    }
  }

  @media (prefers-contrast: more) {
    :scope {
      --line: rgba(23, 24, 27, 0.32);
      --hair: rgba(23, 24, 27, 0.3);
      --muted: #4a4d54;
    }
  }
}
