/*
 * The hand-written styles the components need wherever they are used: the
 * theme scope, the size of an icon and the focus ring. The site imports this
 * file, and the package ships it as components.css, so a component looks and
 * behaves the same in another app. A value here is a token variable, never a
 * number of its own.
 */

@layer base {
  [data-theme] {
    background: var(--color-surface-base);
    color: var(--color-text-default);
  }

  /* Native form controls, such as a checkbox or the arrow of a date field, follow the theme they stand in. */
  [data-theme='light'] {
    color-scheme: light;
  }

  [data-theme='dark'] {
    color-scheme: dark;
  }
}

/*
 * An icon is part of the text (Figma: Presentation, Icons). Next to running
 * text it is 1.5 times the text size, kept on the 4 px grid. Its stroke
 * grows at half the pace of the icon: stroke = (size + 16) / 24, so 1.33 px
 * at 16, 1.5 at 20, 1.67 at 24 and 2.17 at 36. The paths carry
 * vector-effect: non-scaling-stroke, so the stroke is in px at every size.
 */
@utility icon {
  --icon-size: calc(var(--icon-scale) * 1em); /* check-system-allow: relative to the text, by Peter's rule */
  display: inline-block;
  flex-shrink: 0;
  width: var(--icon-size);
  height: var(--icon-size);
  stroke-width: calc((var(--icon-size) + var(--spacing-inline-4)) / 24);
  vertical-align: middle;

  @supports (width: round(nearest, 1em, 1px)) { /* check-system-allow: a feature test, not a size */
    --icon-size: round(nearest, calc(var(--icon-scale) * 1em), var(--spacing-inline-1)); /* check-system-allow: relative to the text, on the 4 px grid */
  }
}

/*
 * The four sizes of the Icon component in Figma, for an icon that does not
 * follow the text around it. Inside a control, such as a button, the icon
 * matches the line height of its text: md beside Body/md and Button/md, sm
 * beside Body/sm.
 */
@utility icon-sm {
  display: inline-block;
  flex-shrink: 0;
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
  stroke-width: var(--icon-stroke-sm);
  vertical-align: middle;
}

@utility icon-md {
  display: inline-block;
  flex-shrink: 0;
  width: var(--icon-size-md);
  height: var(--icon-size-md);
  stroke-width: var(--icon-stroke-md);
  vertical-align: middle;
}

@utility icon-lg {
  display: inline-block;
  flex-shrink: 0;
  width: var(--icon-size-lg);
  height: var(--icon-size-lg);
  stroke-width: var(--icon-stroke-lg);
  vertical-align: middle;
}

@utility icon-xl {
  display: inline-block;
  flex-shrink: 0;
  width: var(--icon-size-xl);
  height: var(--icon-size-xl);
  stroke-width: var(--icon-stroke-xl);
  vertical-align: middle;
}

/*
 * Keyboard focus. Figma has no focus state yet, so this one is ours until
 * Peter draws one: a ring in the text colour, clear of the control.
 */
@utility focus-ring {
  &:focus-visible {
    outline: 2px solid var(--color-text-default); /* check-system-allow: focus ring, not in Figma yet */
    outline-offset: 2px; /* check-system-allow: focus ring, not in Figma yet */
  }
}

/* The same ring on a stretched link, drawn around the card it covers. */
@utility focus-ring-after {
  &:focus-visible::after {
    outline: 2px solid var(--color-neutral-900); /* check-system-allow: focus ring, not in Figma yet */
    outline-offset: -2px; /* check-system-allow: focus ring, not in Figma yet */
  }
}
