/*
 * THE LABELLED ACTION. `data-variant` carries emphasis and `data-tone` valence, so
 * `[data-tone="danger"]` is one selector. Per §2.3, a surface ground takes the neutral wash ladder
 * and a solid ground the on-solid strengths mixed against itself; a destructive act rests on its red
 * tint or ground and, pointed at, turns solid, since a neutral wash over red reads as greyed out.
 */
@layer theme, base, lotics, components, utilities;
@layer lotics.tokens, lotics.reset, lotics.components;

@layer lotics.components {
  .lotics-button {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    /* A shrunk button is a verb nobody can read. */
    flex-shrink: 0;
    min-width: 0;
    position: relative;
    height: var(--lotics-control-height);
    /* The control's inset and icon gutter, written as rungs. */
    padding-inline: var(--lotics-space-10);
    gap: var(--lotics-space-6);
    border: 0 solid var(--border);
    border-radius: var(--lotics-radius-control);
    background-color: transparent;
    background-image: none;
    /* §5 rule 1: a `<button>` hands the UA's 13.33px font to what it holds. */
    font-family: var(--font-sans);
    font-size: var(--lotics-text-sm);
    line-height: var(--lotics-leading-sm);
    letter-spacing: var(--lotics-tracking-sm);
    color: var(--lotics-ink-default);
    --lotics-icon-color: currentColor;
    appearance: none;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    transition: background-color var(--lotics-duration-fast) var(--lotics-ease-standard);
  }

  .lotics-button:focus-visible {
    outline: var(--lotics-ring-width) solid var(--ring);
    outline-offset: 0;
  }

  .lotics-button__label {
    font-family: var(--font-sans);
    font-size: var(--lotics-text-sm);
    line-height: var(--lotics-leading-sm);
    letter-spacing: var(--lotics-tracking-sm);
    font-weight: var(--lotics-weight-medium);
    color: inherit;
    /* A verb that wraps has stopped being a button. */
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .lotics-button[data-align="flex-start"] {
    align-self: flex-start;
  }
  .lotics-button[data-align="flex-end"] {
    align-self: flex-end;
  }
  .lotics-button[data-align="center"] {
    align-self: center;
  }
  .lotics-button[data-align="stretch"] {
    align-self: stretch;
  }
  .lotics-button[data-align="auto"] {
    align-self: auto;
  }

  /* Every action stands on a ground, or it reads as words. The dismiss (`muted`) leaves without doing
     anything, so it stands on none: its ink says it, and hover brings the wash. */
  .lotics-button[data-variant="secondary"] {
    background-color: var(--secondary);
    color: var(--secondary-foreground);
  }

  .lotics-button[data-variant="muted"] {
    color: var(--lotics-ink-muted);
  }

  .lotics-button[data-tone="danger"] {
    color: var(--lotics-ink-danger);
  }

  .lotics-button[data-variant="tonal"][data-tone="danger"] {
    background-color: var(--lotics-wash-danger);
  }

  .lotics-button[data-variant="primary"] {
    background-color: var(--primary);
    color: var(--lotics-ink-on-inverse);
    /* The sheen is the ground's own ink at low alpha, so it holds over any themed hue. */
    box-shadow:
      inset 0 1px 0 color-mix(in srgb, var(--primary-foreground) 8%, transparent),
      0 1px 2px color-mix(in srgb, var(--lotics-shadow-color) 18%, transparent);
    background-image: linear-gradient(
      180deg,
      color-mix(in srgb, var(--primary-foreground) 14%, transparent) 0%,
      transparent 100%
    );
  }

  /*
   * An outside brand is off the kit's ladder, so it arrives as data. A waiting button keeps it; a
   * disabled one falls back to its variant's wash.
   */
  .lotics-button[data-brand]:not([data-disabled]) {
    background-color: var(--lotics-button-brand);
    color: var(--lotics-ink-on-inverse);
  }
  .lotics-button[data-brand][data-loading] {
    background-color: var(--lotics-button-brand);
  }

  /*
   * §2.3: a page button has no selected state to collide with, and the 2% row rung is invisible on
   * a page ground.
   */
  .lotics-button:not([data-disabled]):hover {
    background-image: linear-gradient(
      0deg,
      var(--lotics-wash-selected),
      var(--lotics-wash-selected)
    );
  }
  .lotics-button:not([data-disabled]):active {
    background-image: linear-gradient(0deg, var(--lotics-wash-press), var(--lotics-wash-press));
  }

  /* Pointed at, a destructive act turns solid under its own ink; pressed, a rung deeper. The ink is
     white, so the rung darkens, as a brand's does. */
  .lotics-button[data-tone="danger"]:not([data-disabled]):hover {
    background-color: var(--destructive);
    background-image: none;
    color: var(--destructive-foreground);
  }
  .lotics-button[data-tone="danger"]:not([data-disabled]):active {
    background-color: color-mix(
      in srgb,
      var(--lotics-shadow-color) var(--lotics-on-solid-press),
      var(--destructive)
    );
    background-image: none;
    color: var(--destructive-foreground);
  }

  .lotics-button[data-variant="primary"]:not([data-disabled]):hover {
    background-color: color-mix(
      in srgb,
      var(--primary-foreground) var(--lotics-on-solid-hover),
      var(--primary)
    );
    background-image: none;
  }
  .lotics-button[data-variant="primary"]:not([data-disabled]):active {
    background-color: color-mix(
      in srgb,
      var(--primary-foreground) var(--lotics-on-solid-press),
      var(--primary)
    );
    background-image: none;
  }

  /* Its ink is white, so lifting toward the ink would wash the colour out. */
  .lotics-button[data-brand]:not([data-disabled]):hover {
    background-color: color-mix(
      in srgb,
      var(--lotics-shadow-color) var(--lotics-on-solid-hover),
      var(--lotics-button-brand)
    );
    background-image: none;
  }
  .lotics-button[data-brand]:not([data-disabled]):active {
    background-color: color-mix(
      in srgb,
      var(--lotics-shadow-color) var(--lotics-on-solid-press),
      var(--lotics-button-brand)
    );
    background-image: none;
  }

  /* Loading keeps its resting ground; only a disabled button takes the wash. */
  .lotics-button[data-disabled] {
    color: var(--lotics-ink-inactive);
    cursor: default;
  }
  .lotics-button[data-variant="primary"][data-disabled] {
    color: var(--lotics-ink-on-inverse);
  }

  .lotics-button[data-disabled]:not([data-loading]) {
    background-image: none;
    box-shadow: none;
  }
  .lotics-button[data-variant="primary"][data-disabled]:not([data-loading]) {
    background-color: var(--lotics-wash-control-press);
  }
  .lotics-button[data-variant="secondary"][data-disabled]:not([data-loading]) {
    background-color: var(--lotics-wash-hover);
  }
  .lotics-button[data-variant="tonal"][data-tone="danger"][data-disabled]:not([data-loading]) {
    background-color: var(--lotics-wash-danger);
  }
}
