.form {
  max-width: 40em;
}

form {
  width: 100%;
  max-width: 40em;

  & > div {
    margin: 1em 0;
  }

  .checkbox-field {
    display: grid;
    grid-template-columns: 2rem auto;
    grid-template-rows: auto auto;
    gap: 0.25em;
    align-items: center;

    input[type=checkbox] {
      appearance: none;
      cursor: pointer;
    }

    input[type=checkbox]::before {
      font-size: 1rem;
      display: block;
      content: "";
      width: 1.5rem;
      height: 1.5rem;
      border: 0.125rem solid var(--link-color);
      border-radius: 0.25em;
      box-sizing: border-box;
    }

    input[type=checkbox]:checked::before {
      background: var(--link-color);
    }

    label {
      cursor: pointer;
    }

    .help-text {
      font-size: 0.875rem;
      color: var(--mid-color);
      margin: 0;
      grid-column: 2;
    }
  }

  .form-group {
    margin: 1.5em 0;

    & > label {
      display: block;
      margin-bottom: 0.5em;
      font-weight: bold;
    }

    .help-text {
      font-size: 0.875rem;
      color: var(--mid-color);
      margin: 0.5em 0 0;
    }
  }

  .radio-group {
    display: flex;
    gap: 1.5em;
    flex-wrap: wrap;
  }

  .radio-field {
    display: flex;
    align-items: center;
    gap: 0.5em;

    input[type=radio] {
      appearance: none;
      cursor: pointer;
      margin: 0;
    }

    input[type=radio]::before {
      content: "";
      display: block;
      width: 1.5rem;
      height: 1.5rem;
      border: 0.125rem solid var(--link-color);
      border-radius: 50%;
      box-sizing: border-box;
      transition: 0.2s ease all;
    }

    input[type=radio]:checked::before {
      border-width: 0.5rem;
      background: var(--bg-color);
    }

    label {
      cursor: pointer;
      margin: 0;
      font-weight: normal;
      color: var(--fg-color);
    }
  }

  .color-picker {
    display: flex;
    gap: 1em;
    flex-wrap: wrap;
  }

  .color-option {
    position: relative;

    input[type=radio] {
      appearance: none;
      cursor: pointer;
      margin: 0;
      position: absolute;
      opacity: 0;
    }

    label {
      cursor: pointer;
      margin: 0;
      display: block;
      width: 2.5em;
      height: 2.5em;
      border-radius: 50%;
      transition: 0.2s ease all;
      position: relative;

      &:hover {
        transform: scale(1.1);
        box-shadow: 0 0.125em 0.5em rgba(0,0,0,0.2);
      }

      &::after {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 1em;
        height: 1em;
        border-radius: 50%;
        background: var(--bg-color);
        opacity: 0;
        transition: 0.2s ease all;
      }
    }

    input[type=radio]:checked + label::after {
      opacity: 1;
    }

    label[data-color="red"] {
      background: oklch(0.60 0.24 25);
    }

    label[data-color="orange"] {
      background: oklch(0.75 0.25 50);
    }

    label[data-color="yellow"] {
      background: oklch(0.82 0.14 90);
    }

    label[data-color="green"] {
      background: oklch(0.75 0.16 130);
    }

    label[data-color="teal"] {
      background: oklch(0.75 0.17 170);
    }

    label[data-color="blue"] {
      background: oklch(0.58 0.22 250);
    }

    label[data-color="purple"] {
      background: oklch(0.70 0.17 290);
    }

    label[data-color="pink"] {
      background: oklch(0.72 0.28 345);
    }

    label[data-color="gray"] {
      background: oklch(0.65 0.02 0);
    }
  }
}

label {
  display: block;
  color: var(--mid-color);
}

input[type=text],
input[type=email],
input[type=password],
textarea {
  font-size: 0.875em;
  display: block;
  box-sizing: border-box;
  width: 100%;
  padding: 0.75em;
  border-radius: 0.5em;
  border: 0.0625rem solid var(--border-color);

  color: var(--fg-color);
  background: var(--bg-color);

  outline: medium solid var(--bg-color);
  transition: 0.3s ease outline;

  &:focus {
    border-color: var(--highlight-color);
    outline: medium solid var(--highlight-color);
  }
}

textarea {
  font-family: inherit;
  min-height: 7em;
}

input[type=submit] {
  font-size: 1em;
  font-weight: bold;
  display: block;
  box-sizing: border-box;
  width: 100%;
  padding: 1em;
  margin-bottom: 1.5em;
  border-radius: 0.5em;
  transition: 0.2s ease all;

  color: black;
  background: var(--highlight-color);
  border: none;

  cursor: pointer;

  &:active {
    border-color: color(display-p3 0.096 0.417 0.718 / 1);
    box-shadow: inset 0 0.125em 0.25em rgba(0,0,0, 0.4), inset 0 0.25em 0.5em rgba(0,0,0,0.2);
  }
}

.input-items {
  display: flex;
  align-items: center;
  justify-content: center;

  input {
    flex: 1;
  }

  a {
    height: 2.375em;
    display: block;
    margin-left: 0.5em;

    &:hover svg * {
      fill: var(--link-hover-color);
    }
  }
  svg {
    height: 100%;

    & * {
      fill: var(--fg-color);
      transition: 0.2s ease all;
    }
  }
}

.form-actions {
  display: flex;
  border: 0.0625rem solid var(--border-color);
  border-radius: 0.5em;
  font-size: 0.875em;

  & > * {
    border-right: 0.0625rem solid var(--border-color);
  }

  & > *:first-child, *:first-child button {
    border-top-left-radius: 0.5em;
    border-bottom-left-radius: 0.5em;
  }

  & > *:last-child, *:last-child button {
    border-top-right-radius: 0.5em;
    border-bottom-right-radius: 0.5em;
    border-right: none;
  }

  & a, button {
    color: var(--fg-color);
    font-family: inherit;
    font-size: inherit;
    font-weight: bold;
    text-align: center;
    background: var(--bg-color);
    cursor: pointer;
    border: none;

    display: flex;
    align-items: center;
    justify-content: center;

    flex: 1;
    padding: 0.5em 0;
    box-sizing: border-box;

    transition: 0.2s ease-out all;

    &:hover {
      text-decoration: none;
      color: var(--fg-color);
      background-color: var(--bg-highlight-color);
    }

    &.danger {
      color: var(--danger-color);
    }

    & svg {
      height: 1.5em;
      margin-right: 0.5em;
    }
  }
  & > form {
    display: block;
    width: initial;
    flex: 1;
    box-sizing: border-box;

    button {
      font-family: inherit;
      font-size: inherit;
      line-height: inherit;

      background: transparent;
      width: 100%;
      border: none;
      cursor: pointer;
    }
  }
}

@media screen and (max-width: 32em) {
  input[type=submit] {
    padding: 1.5em 1em;
  }
  .form-actions {
    flex-direction: column;
    & > * {
      border: none;
      border-bottom: 0.0625rem solid var(--border-color);
    }

    & > *:first-child, *:first-child button {
      border-top-left-radius: 0.5em;
      border-top-right-radius: 0.5em;
      border-bottom-left-radius: initial;
    }

    & > *:last-child, *:last-child button {
      border-top-right-radius: initial;
      border-bottom-right-radius: 0.5em;
      border-bottom-left-radius: 0.5em;
      border-bottom: none;
    }

    & a, button {
      padding: 1em 0;
    }
  }
}
