/* ─── shape ──────────────────────────────────────────────────────────────────
 * The slanted corner: `.np-cut` cuts the bottom-right corner off a button, card
 * or code block. `clip-path` clips everything drawn on the element, border and
 * focus ring included, so the parts are layered rather than one box:
 *
 *   ::before   the border colour, clipped to the cut shape
 *   ::after    the fill, inset 1px and clipped to a slightly smaller cut, so what
 *              shows of ::before is a 1px border that follows the diagonal
 *   the element itself is NOT clipped, so its focus outline is a full 2px ring
 *              around the whole box and the cut cannot slice it (3:1, AC-6)
 *
 * Size comes from `--cut`: 9px on buttons (the default), 6px on small buttons
 * (`np-cut--sm`), 16px on cards and code blocks (`np-cut--lg`). Colours are
 * tokens, overridable per element through `--cut-border` and `--cut-fill`.
 * ─────────────────────────────────────────────────────────────────────────── */

.np-cut {
  --cut: 9px;
}

/* :where() keeps these base declarations at zero specificity, so a component's
   own position, border or background wins instead of losing on import order. */
:where(.np-cut) {
  position: relative;
  isolation: isolate;
  border: 0;
  background: transparent;
}

.np-cut--sm {
  --cut: 6px;
}

.np-cut--lg {
  --cut: 16px;
}

.np-cut::before,
.np-cut::after {
  content: "";
  position: absolute;
  z-index: -1;
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%);
}

.np-cut::before {
  inset: 0;
  background: var(--cut-border, var(--c-outline-control));
}

/* A 1px inset moves the diagonal 1.41px along each axis, so the inner cut is
   shorter than the outer by 0.59px for the two edges to stay parallel. */
.np-cut::after {
  inset: 1px;
  background: var(--cut-fill, var(--c-surface));
  clip-path: polygon(
    0 0,
    100% 0,
    100% calc(100% - var(--cut) + 0.59px),
    calc(100% - var(--cut) + 0.59px) 100%,
    0 100%
  );
}

.np-cut:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

@media (forced-colors: active) {
  .np-cut::before {
    background: CanvasText;
  }

  .np-cut::after {
    background: Canvas;
  }

  .np-cut:focus-visible {
    outline-color: Highlight;
  }
}
