/*
  accordion.css
  ---------------------------------------------------------------------
  Styles a native <details>/<summary> disclosure widget. No JavaScript
  and no ARIA attributes to manage by hand - the browser owns the
  open/closed state, the keyboard handling (Enter/Space on the
  <summary>), and the accessibility tree.

  interpolate-size is declared below on .accordion itself rather than
  globally on <html> in reset.css, so a page that links this file gets
  the height animation without the framework imposing a feature that
  isn't yet Baseline on every project. See the comment on that line
  for the reasoning.

  Requires: css/reset.css, css/core.css

  HTML STRUCTURE:
    <details class="accordion">
      <summary class="accordion__summary">Question text</summary>
      <div class="accordion__content">
        <p>Answer content.</p>
      </div>
    </details>

  EXCLUSIVE GROUPS:
    Give several <details class="accordion"> elements the same name
    attribute (name="faq") and the browser closes the others when one
    opens. No CSS or JavaScript involved.

  CUSTOMISING THE MARKER:
    The +/45deg rotation comes from .accordion__summary::after. See the
    ACCORDION block in css/custom.css for a worked override that swaps
    it for a down-arrow.
  ---------------------------------------------------------------------
*/

@layer components {
  .accordion {
    /* Needed for the height: 0 -> auto transition below to interpolate
       smoothly instead of snapping. Scoped here rather than declared
       globally - interpolate-size isn't yet Baseline (Chromium-only
       as of this writing; see docs/index.html's browser support
       policy), below this project's bar for a framework-wide feature.
       Degrades gracefully: the accordion still opens/closes on
       unsupported browsers, it just doesn't animate. */
    interpolate-size: allow-keywords;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
  }

  .accordion__summary {
    padding: var(--space-4);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;

    /* A plain <summary> keeps its native disclosure marker; this one
       gets it removed because ::after below provides a custom +/x
       indicator instead. */
    list-style: none;
  }

  .accordion__summary::-webkit-details-marker {
    display: none;
  }

  .accordion__summary:focus-visible {
    outline-offset: -3px;
  }

  .accordion__summary::after {
    content: "+";
    color: var(--color-accent-text);
    font-size: 1.375rem;
    transition: transform var(--transition-fast);
  }

  .accordion[open] .accordion__summary {
    border-block-end: 1px solid var(--color-border);
  }

  .accordion[open] .accordion__summary::after {
    transform: rotate(45deg);
  }

  .accordion__content {
    padding: var(--space-4);
    color: var(--color-muted);
  }

  .accordion::details-content {
    height: 0;
    overflow: hidden;
    transition: height var(--transition-base);
  }

  @supports (transition-behavior: allow-discrete) {
    .accordion::details-content {
      transition: height var(--transition-base),
        content-visibility var(--transition-base) allow-discrete;
    }
  }

  .accordion[open]::details-content {
    height: auto;
  }

  @starting-style {
    .accordion[open]::details-content {
      height: 0;
    }
  }
}
