@layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
@layer cinder.components {
  /* ========================================
 * LINK
 * Inline text link for use inside prose/body content.
 * For wayfinding links in nav bars or sidebars, use NavigationItem.
 * ======================================== */

  .cinder-link {
    color: var(--cinder-accent-text);
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    line-height: inherit;
    text-decoration: underline;
    text-underline-offset: 0.15em;

    transition: color var(--cinder-duration-fast) var(--cinder-ease-standard);
  }

  /* ----------------------------------------
 * Color variants
 * ---------------------------------------- */

  .cinder-link[data-color='primary'] {
    color: var(--cinder-accent-text);
  }

  .cinder-link[data-color='inherit'] {
    color: inherit;
  }

  /* ----------------------------------------
 * More: the way out of a section or an empty row to the page that holds the rest
 * ("Open Reviews ›"). Small regular text and a chevron, on one line, so it never reads louder
 * than the heading beside it. The face is the text's own; a hit area that takes no layout
 * reaches 24px under a mouse and 44px under a coarse pointer, as a compact button's does.
 * ---------------------------------------- */

  .cinder-link[data-cinder-touch-target],
  .cinder-link[data-variant='more'] {
    /* @runtime-state */
    --_cinder-link-hit: 1.5rem;

    position: relative;
  }

  .cinder-link[data-variant='more'] {
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: var(--cinder-space-0-5);
    font-size: var(--cinder-text-sm);
    font-weight: var(--cinder-font-normal);
    line-height: var(--cinder-leading-snug);
    white-space: nowrap;
  }

  .cinder-link__chevron {
    flex: none;
    inline-size: 1em;
    block-size: 1em;
  }

  /* The hit area takes no layout: at least 24px under a mouse and 44px under a coarse pointer
   * (WCAG 2.5.8 and 2.5.5), centred on the face. Only the more variant stacks above what follows
   * it, so a positioned list row never paints over the bottom of its area (COR-2329). */
  .cinder-link[data-cinder-touch-target]::before,
  .cinder-link[data-variant='more']::before {
    content: '';
    position: absolute;
    /* The height is stated, so the hit area is exactly the hit variable (44px on a coarse pointer).
     * Deriving it as the face less two insets left it a layout unit short in Chromium (43.9844px
     * on a coarse pointer, COR-2809). The face still wins when it is taller than the hit area. */
    block-size: max(100%, var(--_cinder-link-hit));
    inset-block-start: calc(50% - max(100%, var(--_cinder-link-hit)) / 2);
    inset-inline: min(0px, calc((100% - var(--_cinder-link-hit)) / 2));
  }

  /* Keep an inline link in its text flow. The extra pixel keeps both 12px
   * edge samples inside the hit box, including the exclusive ending edge. */
  @media (pointer: fine) {
    a.cinder-link:not([data-cinder-touch-target], [data-variant='more']) {
      position: relative;
    }

    /* A following link's enlarged halo must not cover the end of a prose link's
     * halo. Keep these controls on top at that boundary without moving either line. */
    :where(p) a.cinder-link:not([data-cinder-touch-target], [data-variant='more']) {
      z-index: 1;
    }

    a.cinder-link:not([data-cinder-touch-target], [data-variant='more'])::before {
      content: '';
      position: absolute;
      block-size: max(100%, calc(1.5rem + 1px));
      inset-block-start: 50%;
      inset-inline: 0;
      transform: translateY(-50%);
    }
  }

  @media (any-pointer: coarse) {
    .cinder-link[data-cinder-touch-target],
    .cinder-link[data-variant='more'] {
      /* @runtime-state */
      --_cinder-link-hit: var(--cinder-touch-target-min);
    }
  }

  /* ----------------------------------------
 * Underline variants
 * ---------------------------------------- */

  .cinder-link[data-underline='always'] {
    text-decoration: underline;
  }

  .cinder-link[data-underline='none'] {
    text-decoration: none;
  }

  .cinder-link[data-underline='hover'] {
    text-decoration: none;
  }

  /* Sticky-hover suppression on touch: wrap hover-only chrome so it doesn't
 * "stick" after tap on touch devices that emulate :hover. */
  @media (hover: hover) {
    .cinder-link[data-underline='hover']:hover:not([data-disabled]) {
      text-decoration: underline;
    }

    .cinder-link[data-underline='none']:hover:not([data-disabled]) {
      text-decoration: none;
    }

    .cinder-link[data-color='primary']:hover:not([data-disabled]) {
      color: var(--cinder-accent-text-hover);
    }
  }

  /* ----------------------------------------
 * Focus visible — transparent outline + box-shadow ring
 * Matches the pattern from button.css and navigation-item.css.
 * ---------------------------------------- */

  .cinder-link:focus-visible {
    outline: var(--cinder-ring-width) solid transparent;
    box-shadow: var(--_cinder-focus-ring-shadow);
    border-radius: 2px;
  }

  /* For underline='hover' and underline='none', keyboard focus must restore the
   * underline so keyboard users get the same affordance as mouse users on hover.
   * This is spec-required: underline='hover' documents "underline on hover and focus". */
  .cinder-link[data-underline='hover']:focus-visible:not([data-disabled]),
  .cinder-link[data-underline='none']:focus-visible:not([data-disabled]) {
    text-decoration: underline;
  }

  /* Forced Colors Mode (Windows High Contrast) — box-shadow rings are invisible;
 * replace with a real outline. */
  @media (forced-colors: active) {
    .cinder-link:focus-visible {
      outline: var(--cinder-ring-width) solid LinkText;
      outline-offset: 3px;
    }
  }

  /* ----------------------------------------
 * Disabled state
 * ---------------------------------------- */

  .cinder-link[data-disabled] {
    color: var(--cinder-text-disabled);
    cursor: not-allowed;
    pointer-events: none;
  }
}
