/* Fredoka font */

@font-face {
  font-display: swap;
  font-family: fredoka;
  font-style: normal;
  font-weight: 400;
  src: url('../../font/Fredoka/fredoka-v17-latin-regular.woff2') format('woff2');
}

@font-face {
  font-display: swap;
  font-family: fredoka;
  font-style: normal;
  font-weight: 700;
  src: url('../../font/Fredoka/fredoka-v17-latin-700.woff2') format('woff2');
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  font-family: fredoka, sans-serif;
  margin: 0;
  padding: 0;
}

main {
  margin: 0 auto;
  max-width: 98.5rem;
  padding: 0 2rem;
}

/* Header stays visible while scrolling */

header {
  position: sticky;
  top: 0;
}

/* Page elements: back link, containers */

main > a {
  color: #007cb7;
  display: inline-block;
  font-weight: 700;
  margin-top: 3rem;
  text-decoration: none;
}

main > a::before {
  color: #000;
  content: '> ';
}

main > a:hover {
  color: #005680;
}

main > h1 {
  margin-top: 2.5rem;
}

.admission {
  background-color: #f6f7f8;
  border: 1px solid #d6d8db;
  border-radius: 0.5rem;
  margin: 2rem 0;
  padding: 2rem;
}

.admission p {
  text-align: justify;
}

.registration {
  padding: 2rem;
}

section.registration h2 {
  margin-bottom: 4rem;
  text-align: center;
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}

legend {
  color: #007cb7;
  float: none;
  font-size: 1.8rem;
  font-weight: 700;
  padding: 0;
  text-align: right;
  width: auto;
}

.optional {
  color: #5c6166;
  display: block;
  font-size: 1.6rem;
  font-weight: 400;
}

#avs-format {
  color: #5c6166;
  font-size: 1.4rem;
  margin: 0;
  text-wrap: balance;
}

label,
select,
input[type='date'] {
  cursor: pointer;
}

/* Desktop: form keeps its width, then shrinks below it (no overflow) */

.form-grid {
  align-items: start;
  display: grid;
  gap: 2rem;
  grid-template-columns:
    minmax(0, 15.8fr) minmax(0, 26.4fr) minmax(0, 15.8fr)
    minmax(0, 26.4fr);
  margin: 0 auto;
  max-width: 100%;
  width: 90.4rem;
}

.field {
  align-items: center;
  display: grid;
  grid-column: span 2;
  grid-template-columns: subgrid;
  min-width: 0;
}

.field > label {
  color: #007cb7;
  font-size: 1.8rem;
  font-weight: 700;
  text-align: right;
}

.field > :not(label, legend) {
  grid-column: 2;
}

.options {
  display: grid;
  gap: 1.2rem;
}

.options label {
  align-items: center;
  display: flex;
}

/* Radio groups: legend and options share one grid row */

fieldset.field {
  display: contents;
}

fieldset.field > legend {
  align-self: center;
}

fieldset.field > .options {
  grid-column: auto;
}

fieldset.field:has([name='registration-form[orientation]']) > .options {
  align-self: center;
}

/* Address: street and postal row are 5px apart */

fieldset.field:has(#street-address) > .options {
  gap: 5px;
}

.field > label[for='avs-number'] {
  grid-row: 1 / 4;
}

input:is([type='radio'], [type='checkbox']) {
  height: 1.6rem;
  margin: 0 1rem 0 0;
  width: 1.6rem;
}

input:is([type='text'], [type='email'], [type='date'], [type='number']),
select {
  border: 1px solid #868e96;
  border-left: 5px solid #868e96;
  border-radius: 0.5rem;
  font: inherit;
  padding: 0.5rem 0.8rem;
  width: 100%;
}

textarea {
  border: 1px solid #868e96;
  border-radius: 0.5rem;
  font: inherit;
  min-height: 15.5rem;
  padding: 0.5rem 0.8rem;
  resize: vertical;
  width: 100%;
}

input:is([type='text'], [type='email'], [type='date'], [type='number']),
textarea {
  appearance: none;
}

input[type='number'] {
  appearance: textfield;
}

input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button {
  /* stylelint-disable-next-line property-no-vendor-prefix */
  -webkit-appearance: none;
  margin: 0;
}

/* Hidden from view, still read by screen readers */

.visually-hidden {
  border: 0;
  clip-path: inset(50%);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

select {
  appearance: none;
  background-color: #fff;
  background-image: url('../../img/icon-arrow-down.svg');
  background-position: right 0.8rem center;
  background-repeat: no-repeat;
  background-size: 1.2rem;
}

.address-row {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  width: 100%;
}

.address-row input {
  min-width: 0;
}

input:is([type='text'], [type='email'], [type='date'], [type='number']):valid,
select:valid {
  border-left-color: #218838;
}

input:is(
    [type='text'],
    [type='email'],
    [type='date'],
    [type='number']
  ):user-invalid,
select:user-invalid {
  border-left-color: #c82333;
}

.field:has(textarea) {
  grid-column: 1 / -1;
}

.field:has(textarea) > textarea {
  grid-column: 2 / -1;
}

.error {
  color: #c82333;
  display: none;
  font-size: 1.4rem;
  margin: 0;
}

.field:has(:user-invalid) .error {
  display: block;
}

button {
  background-color: #007cb7;
  border: 2px solid #000;
  border-radius: 0.5rem;
  color: #fff;
  cursor: pointer;
  display: block;
  font: inherit;
  font-size: 1.8rem;
  font-weight: 700;
  margin: 4rem auto 2rem;
  padding: 0.8rem 4.8rem;
}

button:hover {
  background-color: #005680;
}

/* Tablet (768px): 2 columns, labels above */

@media (width <= 768px) {
  .form-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: 68.5rem;
  }

  .field > label[for='avs-number'] {
    grid-row: auto;
  }

  .field {
    grid-column: span 1;
    grid-template-columns: minmax(0, 1fr);
  }

  .field > label {
    margin-bottom: 0.8rem;
    text-align: left;
  }

  .field > :not(label, legend) {
    grid-column: 1;
  }

  .field:has(textarea) {
    grid-column: 1 / -1;
  }

  .field:has(textarea) > textarea {
    grid-column: 1;
  }

  fieldset.field {
    display: block;
    grid-column: span 1;
  }

  legend {
    float: none;
    text-align: left;
    width: auto;
  }

  fieldset.field > legend {
    margin-bottom: 0.8rem;
  }

  .options {
    grid-column: auto;
    grid-row: auto;
  }
}

/* Small smartphone landscape (480px): 1 column, labels on the left */

@media (width <= 480px) {
  .form-grid {
    column-gap: 2rem;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    width: 40rem;
  }

  legend {
    text-wrap: balance;
  }

  .field {
    grid-column: span 2;
    grid-template-columns: subgrid;
  }

  fieldset.field {
    display: contents;
  }

  .field > label {
    text-align: left;
  }

  .field > :not(label, legend) {
    grid-column: 2;
  }

  .field:has(textarea) {
    grid-column: 1 / -1;
    grid-template-columns: 1fr;
  }

  .field:has(textarea) > textarea {
    grid-column: 1;
  }

  fieldset.field > legend {
    align-self: center;
    grid-column: 1;
    text-align: left;
  }

  .options {
    grid-column: 2;
  }
}

/* Smartphone portrait (430px): 1 column, labels above */

@media (width <= 430px) {
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
    width: 35rem;
  }

  .field {
    grid-column: 1;
    grid-template-columns: minmax(0, 1fr);
  }

  .field > label {
    margin-bottom: 0.8rem;
    text-align: left;
  }

  legend .optional {
    display: inline;
  }

  .field > :not(label, legend) {
    grid-column: 1;
  }

  .field:has(textarea) {
    grid-column: 1;
  }

  fieldset.field {
    display: block;
    grid-column: 1;
  }

  legend {
    float: none;
    text-align: left;
    width: auto;
  }

  fieldset.field > legend {
    margin-bottom: 0.8rem;
  }

  .options {
    grid-column: auto;
    grid-row: auto;
  }
}
