/* Shared states of text fields on every page (index.html and the editor pages), docs/UI-RULES.md.
   Linked right after tokens.css, so page styles can still restyle a field; they keep these two rules:

   1. Focus: one indicator. The field's own border turns accent and gets a soft 3px halo; no outline drawn outside
      it (an outline plus the field's border reads as two frames). Buttons and links keep the outline ring
      (community.css / style.css button:focus-visible).
   2. Autofill: Chrome paints autofilled fields light blue over our colours. A full-size inset shadow in the
      field's own background (--fc-field-bg, default surface) paints it back. A field with another background
      sets --fc-field-bg next to its background (and again for :focus if that changes it). */

:is(
  input:not([type]),
  input[type='text'],
  input[type='email'],
  input[type='password'],
  input[type='search'],
  input[type='url'],
  input[type='tel'],
  input[type='number'],
  input[type='date'],
  input[type='datetime-local'],
  input[type='time'],
  textarea,
  select
):focus-visible {
  outline: none;
  border-color: var(--fc-color-accent);
  box-shadow: 0 0 0 3px
    var(
      --fc-field-halo,
      color-mix(in srgb, var(--fc-color-accent) 22%, transparent)
    );
}

/* Separate rules: a browser that does not know one of the two pseudo-classes drops only that rule. */
input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-text-fill-color: var(--fc-color-text);
  caret-color: var(--fc-color-text);
  box-shadow: inset 0 0 0 1000px var(--fc-field-bg, var(--fc-color-surface));
}
input:autofill,
textarea:autofill,
select:autofill {
  -webkit-text-fill-color: var(--fc-color-text);
  caret-color: var(--fc-color-text);
  box-shadow: inset 0 0 0 1000px var(--fc-field-bg, var(--fc-color-surface));
}
input:-webkit-autofill:focus-visible,
textarea:-webkit-autofill:focus-visible {
  box-shadow:
    inset 0 0 0 1000px var(--fc-field-bg, var(--fc-color-surface)),
    0 0 0 3px
      var(
        --fc-field-halo,
        color-mix(in srgb, var(--fc-color-accent) 22%, transparent)
      );
}
input:autofill:focus-visible,
textarea:autofill:focus-visible {
  box-shadow:
    inset 0 0 0 1000px var(--fc-field-bg, var(--fc-color-surface)),
    0 0 0 3px
      var(
        --fc-field-halo,
        color-mix(in srgb, var(--fc-color-accent) 22%, transparent)
      );
}

/* 3. Waiting for the server (docs/UI-RULES.md §7). A button, link or [role=button] that started a request carries
      aria-busy="true" (busy.js, src/ui/Button.tsx busy) until the answer comes back; so does the <label> of a file
      picker while the files upload. While busy it is disabled, keeps its size (the label stays in place but is not
      painted) and shows a spinner in the label's colour where the label was; it does not fade like a plain
      disabled button. .fc-spinner is the same spinner inline, next to a line of text (確認しています…). */
@keyframes fc-spin {
  to {
    transform: rotate(1turn);
  }
}
.fc-spinner {
  display: inline-block;
  flex: none;
  box-sizing: border-box;
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.15em;
  animation: fc-spin 0.7s linear infinite;
}
/* Zero specificity: a button that is already positioned (absolute, fixed, sticky) keeps that. */
:where(button, a, label, [role='button'])[aria-busy='true'] {
  position: relative;
}
:is(button, a, label, [role='button'])[aria-busy='true'] {
  cursor: wait;
  opacity: 1;
  -webkit-text-fill-color: transparent;
}
/* Links and labels cannot be disabled; they ignore clicks instead, so the request is not sent twice. */
:is(a, label, [role='button']:not(button))[aria-busy='true'] {
  pointer-events: none;
}
:is(button, a, label, [role='button'])[aria-busy='true'] > * {
  visibility: hidden;
}
:is(button, a, label, [role='button'])[aria-busy='true']::before {
  /* Some buttons draw an icon or a badge in ::before; it is part of the label. */
  visibility: hidden;
}
:is(button, a, label, [role='button'])[aria-busy='true']::after {
  content: '';
  position: absolute;
  inset: 0;
  display: block;
  box-sizing: border-box;
  width: 1.1em;
  min-width: 14px;
  height: 1.1em;
  min-height: 14px;
  margin: auto;
  padding: 0;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  background: none;
  box-shadow: none;
  opacity: 1;
  transform: none;
  visibility: visible;
  pointer-events: none;
  animation: fc-spin 0.7s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  /* Still turning (it is the only sign that something is happening), just slower. */
  .fc-spinner,
  :is(button, a, label, [role='button'])[aria-busy='true']::after {
    animation-duration: 1.6s;
  }
}
