/* ==========================================================================
   Toggler — a button that switches something on and off.

   <button class="btn btn-icon" data-moey-toggle aria-label="Star">          ← its own on / off
     <i class="mi mi-star toggler-off"></i><i class="mi mi-star-filled toggler-on"></i>
   </button>
   <button class="btn" data-moey-toggle="#app" data-moey-toggle-class="is-compact">Compact</button>
   <button class="btn" data-moey-toggle="#filters">Filters</button>          ← shows / hides it

   moey.js keeps aria-pressed (or aria-expanded when it shows / hides) on the button.
   .toggler-on / .toggler-off   parts shown only while it's on / off
   .toggler-icon                a menu icon that turns into an ×
   .toggler-icon-plus           a + that turns into a −
   data-moey-persist="key"      remembers the state on this device
   (For a smooth height animation when showing / hiding, use Collapse.)
   ========================================================================== */

/* On / off parts */
:is([aria-pressed="true"], [aria-expanded="true"]) > .toggler-off,
:not([aria-pressed="true"], [aria-expanded="true"]) > .toggler-on { display: none !important; }   /* !important: icon fonts load outside Moey's layers */

/* Animated icons — sized like an icon (1.25em), drawn in the text color */
.toggler-icon,
.toggler-icon-plus {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
  width: 1.125em;
  height: 1.125em;
  vertical-align: -.2em;
}
.toggler-icon::before,
.toggler-icon::after,
.toggler-icon-plus::before,
.toggler-icon-plus::after {
  position: absolute;
  inset-inline: .0625em;
  top: calc(50% - .0625em);
  height: .125em;
  content: "";
  background: currentColor;
  border-radius: 1em;
}
/* Menu → ×: three bars; the middle one fades, the outer two turn into a cross */
.toggler-icon::before { translate: 0 -.3125em; }
.toggler-icon::after { translate: 0 .3125em; }
.toggler-icon { background: linear-gradient(currentColor 0 0) center / calc(100% - .125em) .125em no-repeat; border-radius: 1em; }
:is([aria-pressed="true"], [aria-expanded="true"]) > .toggler-icon::before { translate: 0; rotate: 45deg; }
:is([aria-pressed="true"], [aria-expanded="true"]) > .toggler-icon::after { translate: 0; rotate: -45deg; }
:is([aria-pressed="true"], [aria-expanded="true"]) > .toggler-icon { background-size: 0 .125em; }
/* + → −: the upright bar lies down */
.toggler-icon-plus::after { rotate: 90deg; }
:is([aria-pressed="true"], [aria-expanded="true"]) > .toggler-icon-plus::after { rotate: 0deg; }
@media (prefers-reduced-motion: no-preference) {
  .toggler-icon::before, .toggler-icon::after, .toggler-icon-plus::after { transition: translate .2s var(--mo-ease), rotate .2s var(--mo-ease); }
  .toggler-icon { transition: background-size .15s var(--mo-ease); }
}
/* A toggle button that is on looks pressed — one step stronger, whatever its color or strength */
.btn[data-moey-toggle][aria-pressed="true"] { background-image: linear-gradient(color-mix(in oklab, currentColor 14%, transparent) 0 0); }
