/* ==========================================================================
   Modals: <dialog class="modal modal--…" data-modal="<name>">.
   Opened and closed by js/header.js (window.modal.open / close).
   Breakpoints: mobile < 768 ≤ desktop (design: 320 and 1920).
   ========================================================================== */

/* The dialog covers the whole viewport and centres its window; a click on
   the dialog itself (outside the window) closes it. The middle grid row is
   the window: the free space is split above and below it, but never less
   than the minimum, so a tall window does not slide under the header. */
.modal {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0 16px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 0;
  background: none;
  color: inherit;
}

/* the window takes focus when the modal opens (autofocus): no ring around
   it, Tab then goes to the close button */
.modal:focus,
.modal__window:focus {
  outline: none;
}

.modal[open] {
  display: grid;
  grid-template-rows: minmax(64px, 1fr) auto minmax(16px, 1fr);
  justify-items: center;
}

/* the page behind: tinted and blurred; on mobile the header stays sharp */
.modal::backdrop {
  top: 48px;
  background: rgba(15, 59, 32, 0.23);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.modal__window {
  position: relative;
  grid-row: 2;
  width: 100%;
  text-align: center;
}

.modal__close {
  position: absolute;
  top: 6px;
  inset-inline-end: 7px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: #57595f;
  cursor: pointer;
}

.modal__close svg {
  display: block;
  width: 24px;
  height: 24px;
  fill: none;
  stroke-width: 1.5;
}

.modal__close:focus-visible {
  outline: 2px solid var(--color-accent-text);
  outline-offset: -2px;
}

/* Opening and closing
   ========================================================================== */

.modal[open] .modal__window {
  animation: modal-in 0.25s ease-out;
}

.modal[open]::backdrop {
  animation: modal-fade 0.25s ease-out;
}

.modal.is-closing .modal__window {
  animation: modal-out 0.2s ease-in forwards;
}

.modal.is-closing::backdrop {
  animation: modal-fade 0.2s ease-in reverse forwards;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
}

@keyframes modal-out {
  to {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
}

@keyframes modal-fade {
  from {
    opacity: 0;
  }
}

/* the page under an open modal does not scroll */
html.is-modal-open {
  overflow: hidden;
  scrollbar-gutter: stable;
}

/* Status: success or error message
   ========================================================================== */

.modal--status {
  padding-inline: 18px;
}

.modal--status .modal__window {
  max-width: 324px;
  padding: 30px 20px 31px;
  border-radius: 20px;
  background: #ffffff;
  color: #221b37;
}

.modal__icon {
  display: block;
  width: 38px;
  height: 33px;
  margin-inline: auto;
}

.modal--status .modal__title {
  margin-top: 6px;
  font-size: 21px;
  font-weight: 600;
  line-height: 24px;
  letter-spacing: 0.015em;
}

.modal--status .modal__text {
  margin-top: 11px;
  font-size: 14px;
  line-height: 17px;
}

/* Discount offer with an email form
   ========================================================================== */

/* Background as in the design: the hexagon pattern in soft-light over the
   dark green, then a gradient to the dark green on the left.
   The pattern is tied to the right edge and grows with wider windows, so it
   always covers them; at 288px it sits exactly as in the design. */
.modal--discount .modal__window {
  max-width: 819px;
  padding: 40px 14px 51px;
  border-radius: 10px;
  background:
    linear-gradient(237.43deg, rgba(9, 105, 84, 0) 50.3%, #06483a 81.8%),
    url("../img/modal-discount-pattern.webp") right -50px top -42px / max(704.6px, 100% + 100px) no-repeat,
    #06483a;
  background-blend-mode: normal, soft-light;
  color: #ffffff;
}

.modal--discount .modal__close {
  top: 7px;
  inset-inline-end: 8px;
  color: #ffffff;
}

.modal--discount .modal__close svg {
  stroke-width: 2;
}

.modal__lead {
  font-size: 16px;
  font-weight: 500;
  line-height: 20px;
}

.modal--discount .modal__title {
  margin-top: 2px;
  font-size: 39px;
  font-weight: 500;
  line-height: 48px;
  letter-spacing: -0.03em;
}

.modal__accent {
  color: #ffc403;
}

.modal--discount .modal__text {
  margin-top: 38px;
  font-size: 14px;
  line-height: 17px;
}

.modal__form {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin-top: 40px;
}

.modal__caption {
  max-width: 210px;
  margin: 0 auto 8px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 12px;
  line-height: 15px;
  text-wrap: balance;
}

.modal__input,
.modal__submit {
  width: 100%;
  max-width: 525px;
}

.modal__input {
  height: 44px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.modal__input::placeholder {
  color: #ffffff;
  opacity: 1;
}

.modal__input:focus {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.25);
  outline: none;
}

.modal__submit {
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--color-accent-strong);
  color: #ffffff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.modal__submit:hover {
  background: var(--color-accent-strong-hover);
}

.modal__submit:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

/* Desktop
   ========================================================================== */

@media (min-width: 768px) {
  .modal[open] {
    grid-template-rows: minmax(16px, 1fr) auto minmax(16px, 1fr);
  }

  .modal::backdrop {
    top: 0;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
  }

  .modal--status .modal__window {
    padding: 40px 20px 43px;
  }

  .modal--status .modal__title {
    margin-top: 4px;
    font-size: 24px;
    line-height: 29px;
  }

  .modal--status .modal__text {
    font-size: 16px;
    line-height: 19px;
  }

  .modal--discount .modal__window {
    padding: 112px 80px 99px;
    background:
      linear-gradient(to left, rgba(9, 105, 84, 0), #06483a),
      url("../img/modal-discount-pattern.webp") -287px -175.5px / 1127px no-repeat,
      #06483a;
    background-blend-mode: normal, soft-light;
  }

  .modal--discount .modal__close {
    top: 18px;
    inset-inline-end: 16px;
  }

  .modal--discount .modal__close svg {
    width: 28px;
    height: 28px;
  }

  .modal__lead {
    line-height: 19px;
  }

  .modal__break {
    display: none;
  }

  .modal--discount .modal__title {
    margin-top: 1px;
    font-size: 54px;
    line-height: 68px;
    letter-spacing: 0;
  }

  .modal--discount .modal__text {
    margin-top: 37px;
    font-size: 20px;
    line-height: 30px;
  }

  .modal__form {
    gap: 16px;
    margin-top: 60px;
  }

  .modal__caption {
    max-width: none;
    margin-bottom: 1px;
    font-size: 16px;
    line-height: 19px;
  }

  .modal__input {
    height: 52px;
    font-size: 16px;
  }

  .modal__submit {
    height: 52px;
    font-size: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal[open] .modal__window,
  .modal[open]::backdrop,
  .modal.is-closing .modal__window,
  .modal.is-closing::backdrop {
    animation: none;
  }
}
