*,
*::before,
*::after {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

:root {
  --green-200: hsl(148, 38%, 91%);
  --green-600: hsl(169, 82%, 27%);
  --red: hsl(0, 66%, 54%);
  --white: hsl(0, 0%, 100%);
  --grey-500: hsl(186, 15%, 59%);
  --grey-900: hsl(187, 24%, 22%);

  --border-radius: 10px;
}

html,
body {
  min-height: 100%;
}

body {
  accent-color: var(--green-600);
  font-family: "Karla", sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--grey-900);
  background: var(--green-200);
}

main {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.container {
  position: relative;
  max-width: 736px;
  width: 90%;
  margin: 2rem auto;
  background: var(--white);
  border-radius: var(--border-radius);
  padding: clamp(1.5rem, 0.5458rem + 4.0712vw, 2.5rem);
}

h1 {
  margin-bottom: 1em;
}

/* General Form Styles */
form {
  display: grid;
  grid-template-columns: 1fr;
}

label {
  font: inherit;
  display: block;
  margin-bottom: 0.5rem;
}

button,
input,
textarea {
  font: inherit;
  width: 100%;
  cursor: pointer;
}

input,
textarea {
  border-radius: var(--border-radius);
  border: 1px solid var(--grey-500);
  font-size: 1.125rem;
  padding: 0.66667em 1.33334em;
  height: 3rem;

  &:focus-visible {
    outline-color: var(--green-600);
  }

  &:hover {
    border-color: var(--green-600);
  }
}

textarea {
  height: calc(3lh + 1.4em); /* 3 line heights + vertical padding */
  resize: block;
}

.required::after {
  content: " *";
  color: var(--green-600);
}

legend {
  margin-bottom: 1rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

fieldset[required] legend,
.form-group:has(:not(fieldset)[required]) label {
  display: flex;
  gap: 1ch;

  &::after {
    content: "*";
    color: var(--green-600);
  }
}

/* Radio */
.radio-set {
  position: relative;
  display: flex;
  flex-direction: column;
  border: none;
  gap: 10px;
}

input[type="radio"] {
  width: 1.1em;
  height: 1.1em;
  border-radius: 50%;
  vertical-align: -4px;
  margin: 0 1rem 0 0;
}

.radio-item {
  border: 1px solid var(--grey-500);
  border-radius: var(--border-radius);
  height: 3rem;
  padding: 0 2rem;
  display: flex;
  align-items: center;

  position: relative;

  label::after {
    content: "";
    position: absolute;
    inset: 0;
  }
}

.radio-item:hover {
  border-color: var(--green-600);
}

.radio-item:has(input[type="radio"]:checked) {
  background: var(--green-200);
}

.radio-item label {
  margin-bottom: 0;
  cursor: pointer;
}

/* Checkbox */
.consent-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 1rem;
  row-gap: 0;

  margin: 0 0 1rem;
}

input[type="checkbox"] {
  width: auto;
  height: auto;
}

.consent-label {
  display: inline;
  cursor: pointer;
  margin-bottom: 0;
}

/* Submit Button */
button {
  appearance: none;
  background: var(--green-600);
  color: var(--white);
  border: none;
  border-radius: 5px;
  padding: 1rem 0;
  width: 100%;
  cursor: pointer;

  font-weight: 700;
  font-size: 1.125rem;
  line-height: 150%;
}

button:hover {
  background-color: hsl(169, 82%, 22%);
}

/* Error state */
.error-message {
  padding-top: 0.25rem;
  color: var(--red);
  display: none;
}

.form-group:has(input:user-invalid),
.form-group:has(textarea:user-invalid) {
  input,
  textarea {
    border-color: var(--red);
  }

  .error-message {
    display: block;
  }
}

.span-all {
  grid-column: 1 / -1;
}

/* Success Message */
.success-message {
  position: absolute;
  top: -1rem;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: fit-content;
  background-color: var(--grey-900);
  border-radius: 0.75rem;
  color: var(--white);
  padding: 1.5rem;
  z-index: 2;
  display: none;

  &.visible {
    display: block;
  }

  .title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    h2 {
      font-size: 1.125rem;
    }
  }
}

@media (min-width: 48rem) {
  form {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem 1rem;
  }

  .form-group {
    margin-bottom: 0;
  }

  .consent-row {
    margin: 1rem 0;
  }

  .radio-set {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }
}
