/*
 * The style of metacore on what a person operates: fields, boxes and
 * buttons. base.css holds the elements of a document, and states the rules
 * of the style: they hold here too. overlays.css holds what opens over the
 * page.
 *
 * A control of the browser comes first: a `<select>`, a `<details>`. Where
 * a component draws its own, such as the button of a `Select`, its look is
 * here, on the ARIA role that the component writes, and its state on the
 * ARIA attribute that says it.
 *
 * This file stays plain CSS in one layer, with no Tailwind syntax.
 */

@layer base {
  /*
   * Forms. A form keeps the width that a person reads in one look, however
   * wide the page around it is: a field the width of the window is no easier
   * to fill.
   */

  form {
    max-width: 40rem;
  }

  label {
    color: var(--ink);
    font-weight: 500;
  }

  fieldset {
    border: 1px solid var(--line);
    padding: 1rem 1.25rem 1.25rem;
  }

  legend {
    padding: 0 0.5rem;
  }

  input:not([type="checkbox"], [type="radio"], [type="range"], [type="file"], [type="color"], [type="button"], [type="submit"], [type="reset"]),
  select,
  textarea {
    background-color: var(--white);
    border: 1px solid var(--stone);
    color: var(--ink);
    font-weight: 400;
    padding: 0.4375rem 0.625rem;
  }

  /*
   * A field of one line is as high as a button, so a field and the button
   * beside it line up: 2rem, a line of 1rem, its padding and its border.
   */
  input:not([type="checkbox"], [type="radio"], [type="range"], [type="file"], [type="color"], [type="button"], [type="submit"], [type="reset"]),
  select:not([multiple], [size]),
  button[role="combobox"] {
    height: 2rem;
    line-height: 1rem;
  }

  ::placeholder {
    color: var(--stone);
  }

  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible {
    border-color: var(--accent);
    outline-offset: 0;
  }

  /* A field is wrong only after the person has left it, never while typing. */
  input:user-invalid,
  select:user-invalid,
  textarea:user-invalid {
    border-color: var(--failed);
    outline-color: var(--failed);
  }

  input:disabled,
  select:disabled,
  textarea:disabled {
    background-color: var(--paper);
    border-color: var(--line);
    color: var(--stone);
    cursor: not-allowed;
  }

  /*
   * Boxes. A checkbox is a square with a check, a radio button is a circle
   * with a dot, as the web always drew them, and a switch is a checkbox with
   * `role="switch"`: a track with a square knob. The browser draws none of
   * them.
   */

  input:is([type="checkbox"], [type="radio"]) {
    appearance: none;
    display: inline-grid;
    flex: none;
    place-content: center;
    width: 1rem;
    height: 1rem;
    background-color: var(--white);
    border: 1px solid var(--stone);
    cursor: pointer;
    vertical-align: -0.1875rem;
  }

  input[type="radio"] {
    border-radius: 50%;
  }

  input:is([type="checkbox"], [type="radio"]):hover {
    border-color: var(--ink);
  }

  input:is([type="checkbox"], [type="radio"])::before {
    content: "";
  }

  input[type="checkbox"]:is(:checked, :indeterminate) {
    background-color: var(--ink);
    border-color: var(--ink);
  }

  /* The check: two sides of a rectangle, turned. */
  input[type="checkbox"]:not([role="switch"]):checked::before {
    width: 0.3125rem;
    height: 0.5625rem;
    border: solid var(--white);
    border-width: 0 0.125rem 0.125rem 0;
    rotate: 45deg;
    translate: 0 -0.0625rem;
  }

  input[type="checkbox"]:not([role="switch"]):indeterminate::before {
    width: 0.5rem;
    height: 0.125rem;
    background: var(--white);
  }

  input[type="radio"]:checked {
    border-color: var(--ink);
  }

  input[type="radio"]:checked::before {
    width: 0.5rem;
    height: 0.5rem;
    background: var(--ink);
    border-radius: 50%;
  }

  input[type="checkbox"][role="switch"] {
    justify-content: start;
    width: 2rem;
    padding-inline: 0.125rem;
  }

  input[type="checkbox"][role="switch"]::before {
    width: 0.625rem;
    height: 0.625rem;
    background: var(--stone);
  }

  input[type="checkbox"][role="switch"]:checked {
    justify-content: end;
  }

  input[type="checkbox"][role="switch"]:checked::before {
    background: var(--white);
  }

  input:is([type="checkbox"], [type="radio"]):disabled {
    border-color: var(--line);
  }

  input[type="checkbox"]:is(:checked, :indeterminate):disabled {
    background-color: var(--stone);
    border-color: var(--stone);
  }

  input[type="radio"]:checked:disabled {
    border-color: var(--stone);
  }

  input[type="radio"]:checked:disabled::before {
    background: var(--stone);
  }

  /* How far a long piece of work is. With no value, the amount is not known. */

  progress {
    appearance: none;
    width: 100%;
    height: 0.5rem;
    background: var(--paper);
    border: 1px solid var(--line);
    vertical-align: baseline;
  }

  progress::-webkit-progress-bar {
    background: var(--paper);
  }

  progress::-webkit-progress-value {
    background: var(--ink);
  }

  progress::-moz-progress-bar {
    background: var(--ink);
  }

  progress:indeterminate,
  progress:indeterminate::-webkit-progress-bar {
    background: repeating-linear-gradient(135deg, var(--line) 0 0.25rem, var(--paper) 0.25rem 0.5rem);
  }

  progress:indeterminate::-moz-progress-bar {
    background: none;
  }

  /*
   * Buttons. A button has an ink line. The button that sends a form is the
   * main action of its screen: it is filled with ink, and turns petrol under
   * the pointer.
   */

  button,
  input:is([type="button"], [type="submit"], [type="reset"]),
  ::file-selector-button {
    background: var(--white);
    border: 1px solid var(--ink);
    color: var(--ink);
    cursor: pointer;
    /* A line of 1rem, so a button is 2rem high, as a field of one line. */
    font: 500 0.8125rem/1rem var(--sans);
    padding: 0.4375rem 0.875rem;
    white-space: nowrap;
  }

  button:hover,
  input:is([type="button"], [type="reset"]):hover {
    background: var(--paper);
  }

  :is(button, input)[type="submit"] {
    background: var(--ink);
    color: var(--white);
  }

  :is(button, input)[type="submit"]:hover {
    background: var(--accent);
    border-color: var(--accent);
  }

  button:active,
  input:is([type="button"], [type="submit"], [type="reset"]):active {
    translate: 0 1px;
  }

  button:disabled,
  input:is([type="button"], [type="submit"], [type="reset"]):disabled {
    background: var(--paper);
    border-color: var(--line);
    color: var(--stone);
    cursor: not-allowed;
    translate: none;
  }

  /*
   * A toolbar of commands, such as the buttons of a tile of a file: a
   * `<menu>` of `<li>`, each with a button. Its buttons are small and
   * quiet, with a line of the color of the lines that turns ink under the
   * pointer, so the commands of each item of a list never bury the item.
   */

  menu {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    list-style: none;
    margin: 0;
    padding: 0;
  }

  menu button {
    border-color: var(--line);
    color: var(--body);
    font-size: 0.75rem;
    padding: 0.1875rem 0.5rem;
  }

  menu button:hover:not(:disabled) {
    background: var(--white);
    border-color: var(--ink);
    color: var(--ink);
  }

  /*
   * A choice from a list. A `<select>`, the button of a `Select` and the
   * field of a `Combobox` or of a `Suggest` are the same field, with a
   * triangle that says it opens.
   */

  select:not([multiple], [size]),
  input[role="combobox"] {
    appearance: none;
    background-image:
      linear-gradient(to top right, transparent 50%, var(--ink) 50%),
      linear-gradient(to top left, transparent 50%, var(--ink) 50%);
    background-position:
      right 0.875rem center,
      right 0.625rem center;
    background-repeat: no-repeat;
    background-size: 0.25rem 0.25rem;
    padding-right: 1.875rem;
  }

  button[role="combobox"] {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    background: var(--white);
    border-color: var(--stone);
    cursor: default;
    font: inherit;
    font-weight: 400;
    padding: 0.4375rem 0.625rem;
    text-align: left;
    translate: none;
  }

  button[role="combobox"][data-placeholder] {
    color: var(--stone);
  }

  button[role="combobox"]:focus-visible {
    border-color: var(--accent);
    outline-offset: 0;
  }

  button[role="combobox"][aria-expanded="true"] {
    border-color: var(--ink);
  }

  button[role="combobox"][aria-invalid="true"] {
    border-color: var(--failed);
    outline-color: var(--failed);
  }

  button[role="combobox"]:disabled {
    background: var(--paper);
    border-color: var(--line);
    color: var(--stone);
    cursor: not-allowed;
  }

  /* The triangle of a button that opens a list. It takes the color of the text. */
  button:is([role="combobox"], [aria-haspopup="menu"])::after {
    content: "";
    display: inline-block;
    flex: none;
    border: solid transparent;
    border-width: 0.25rem 0.25rem 0;
    border-top-color: currentColor;
    margin-inline-start: 0.625rem;
    vertical-align: middle;
  }

  /* While its menu is open, the button is an ink block. */
  button[aria-haspopup="menu"][aria-expanded="true"] {
    background: var(--ink);
    color: var(--white);
  }

  /* A part that folds. */

  summary {
    color: var(--ink);
    cursor: pointer;
    font-weight: 500;
  }
}
