/*
 * The first-visit cookie banner (M2-LEGALPAGES; UI-13): a card at the bottom right of every public page until the visitor chooses.
 * At most 414 px wide (the MUD card), 8 px from the edges under 480 px, never taller than the window (it scrolls inside itself, so
 * it fits 320x256 - at 400 px of height or less it sits in the page's flow instead), a region named by its heading, first in the tab order after the skip link. The page gets bottom padding while
 * it is shown, so the legal bar is never covered. Values come from tokens.css.
 */
.cookie-banner {
  position: fixed;
  z-index: 40;
  right: var(--spacing-8);
  bottom: var(--spacing-8);
  left: var(--spacing-8);
  max-height: calc(100dvh - var(--spacing-16));
  max-width: var(--size-414px);
  margin-inline-start: auto;
  overflow-y: auto;
  padding: var(--spacing-16);
  border: var(--border-width-1) solid var(--color-border);
  border-radius: var(--border-radius-12);
  background: var(--color-surface);
  box-shadow: var(--shadow-100);
  font-size: var(--font-size-14);
  line-height: var(--line-height-20);
  /* MO-5: in over the base duration (see the motion block below) */
  opacity: 1;
  transform: none;
  transition:
    opacity var(--motion-duration-base) var(--motion-easing-standard),
    transform var(--motion-duration-base) var(--motion-easing-standard),
    display var(--motion-duration-base) var(--motion-easing-standard) allow-discrete;
}

@media (min-width: 480px) {
  .cookie-banner {
    right: var(--spacing-24);
    bottom: var(--spacing-24);
    left: auto;
    max-height: calc(100dvh - var(--spacing-48));
    padding: var(--spacing-24);
  }
}

.cookie-banner__title {
  margin: 0 0 var(--spacing-8);
  font-size: var(--font-size-20);
  line-height: var(--line-height-28);
  letter-spacing: var(--letter-spacing-h4);
  font-weight: var(--font-weight-medium);
}

.cookie-banner p {
  margin: 0 0 var(--spacing-12);
}

.cookie-banner .cookie-banner__title {
  margin: 0 0 var(--spacing-8);
}

.cookie-banner a {
  color: var(--color-link);
  text-decoration: underline;
  text-underline-offset: var(--underline-offset);
}

/* Two equal buttons side by side, the same style: neither is the primary one (UI-13) */
.cookie-banner__actions {
  display: flex;
  gap: var(--spacing-8);
}

.cookie-banner__actions .button {
  flex: 1 1 0;
  min-width: 0;
  padding-inline: var(--spacing-8);
}

/* Once a choice is made the banner stays in the page, hidden; the footer's link to it shows it without a script */
.cookie-banner[hidden]:target {
  display: block;
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* MO-5: the banner enters with opacity and translateY(16px) -> 0 over --motion-duration-base (on a first visit, and when the footer's
   link shows it again) and leaves the same way over --motion-duration-fast when a choice hides it. The hidden attribute stays what
   hides it (display: none, kept through the exit by allow-discrete); a browser without @starting-style or allow-discrete shows and
   hides it at once. Under reduced motion the durations are 0 and the banner does not move. */
.cookie-banner[hidden] {
  display: none;
  opacity: 0;
  transform: translateY(var(--spacing-16));
  pointer-events: none;
  transition:
    opacity var(--motion-duration-fast) var(--motion-easing-standard),
    transform var(--motion-duration-fast) var(--motion-easing-standard),
    display var(--motion-duration-fast) var(--motion-easing-standard) allow-discrete;
}

@starting-style {
  .cookie-banner {
    opacity: 0;
    transform: translateY(var(--spacing-16));
  }
}

@media (prefers-reduced-motion: reduce) {
  .cookie-banner,
  .cookie-banner[hidden] {
    transform: none;
  }
}

/* The page makes room for the banner, so it never covers the legal bar; the script sets the exact height */
body:has(.cookie-banner:not([hidden]), .cookie-banner:target) {
  padding-bottom: var(--cookie-banner-space, var(--size-15rem));
}

/* a11y-15: the focus scroll leaves the focused control clear of the banner. The scrollport's bottom edge for it is the banner's top (the
   script sets --cookie-banner-space to the banner's height and the margin under it), so Tab never lands a control under the card. */
html:has(.cookie-banner:not([hidden]), .cookie-banner:target) {
  scroll-padding-bottom: var(--cookie-banner-space, var(--size-15rem));
}

/* a11y-15: a window of 400 px or less (a phone turned on its side, 320 x 256) has no room for a card that stays over the page: the banner
   sits in the page's flow, first after the skip link, and pushes the page down instead of covering it. Its title, text and both buttons
   show in full and it has no scroll of its own; the page keeps no room for it at its bottom and the focus scroll has nothing to clear. */
@media (max-height: 400px) {
  .cookie-banner {
    position: static;
    max-height: none;
    margin: var(--spacing-8);
    margin-inline-start: auto;
    overflow: visible;
  }

  html body:has(.cookie-banner:not([hidden]), .cookie-banner:target) {
    padding-bottom: 0;
  }

  html:has(.cookie-banner:not([hidden]), .cookie-banner:target) {
    scroll-padding-bottom: 0;
  }
}

@media print {
  .cookie-banner,
  .cookie-banner[hidden]:target {
    display: none;
  }
}
