/* Consent in one line, in the minimal style: a white page and, at the bottom in the middle, a capsule with one
   sentence in Archivo (a variable sans, weight 100 to 900 and width 62 to 125) and two pills. One vermilion for the
   line that strikes a word. The script places the words, moves them and writes their weight and width. */
:root {
  --page: #ffffff;                 /* the page */
  --surface: #ffffff;              /* the capsule */
  --ink: #141414;                  /* the words and the main pill */
  --grey: #a19c93;                 /* a struck word, the small link */
  --rule: #e6e2da;                 /* the capsule's hairline and the line under a word that can be struck */
  --accent: #e5432b;               /* the line that strikes a word */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Archivo Variable', 'Archivo', 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- the banner */
/* the banner sits in the lower half, near the middle of the page, so the demo is balanced: on a real site --gap
   goes back to a small margin from the bottom (28px) */
.consent {
  --gap: max(28px, calc(50svh - 60px));
}

.banner {
  --fs: clamp(18px, 1.62vw, 24px);
  --pad: 14px;
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--gap) + env(safe-area-inset-bottom, 0px));
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 28px;
  width: fit-content;
  max-width: calc(100vw - 32px);
  margin: 0 auto;
  padding: var(--pad) var(--pad) var(--pad) calc(var(--pad) + 18px);
}

/* the capsule: a layer of its own, so it can follow the sentence when it changes length and close into a line */
.banner__frame {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border-radius: 40px;
  background: var(--surface);
  /* --sh goes to 0 as the capsule closes into a line: no hairline, no shadow */
  --sh: 1;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--rule) calc(var(--sh, 1) * 100%), transparent), 0 1px 2px rgba(20, 20, 20, calc(0.04 * var(--sh, 1))), 0 18px 40px -22px rgba(20, 20, 20, calc(0.22 * var(--sh, 1)));
  pointer-events: none;
}

/* ---------------------------------------------------------------- the sentence */
.sentence {
  --space: 0.26em;
  position: relative;
  display: flex;
  /* on one line, and allowed to be narrower than its words: while the banner is held at its new width the words
     run past the box instead of pushing the pills */
  flex: 0 1 auto;
  min-width: 0;
  flex-wrap: nowrap;
  align-items: flex-start;
  column-gap: var(--space);
  margin: 0;
  font-size: var(--fs);
  line-height: 1.28;
  letter-spacing: -0.012em;
  white-space: nowrap;
}

/* a word, a comma or a full stop: the script moves it (FLIP), its lift hops and folds, its text takes the axes */
/* a word holds the comma or full stop that follows it, so they never part at the end of a line */
.tok {
  position: relative;
  display: flex;
  flex: none;
}

.tok__lift {
  position: relative;
  display: block;
  transform-origin: 50% 58%;
}

/* the text holds its hairline and its strike, so they are always as long as the letters */
.tok__text {
  position: relative;
  display: inline-block;
  white-space: nowrap;
  font-variation-settings: 'wght' 330, 'wdth' 100;
}

/* the kinds are buttons that look like words */
button.tok {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button.tok[aria-disabled='true'] {
  cursor: default;
}

/* the hairline under a word that can be struck: it says the word can be touched; it does not move with the mouse */
.tok__hint {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--hint-y, 1.12em);
  height: 1px;
  background: var(--rule);
  pointer-events: none;
}

/* the line that strikes: through the middle of the small letters (the script measures where that is) */
.tok__strike {
  position: absolute;
  left: -0.08em;
  right: -0.08em;
  top: var(--strike-y, 0.7em);
  height: 1.5px;
  margin-top: -0.75px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: 0 50%;
  pointer-events: none;
}

button.tok:focus-visible {
  outline: none;
}

button.tok:focus-visible > .tok__lift {
  outline: 1.5px solid var(--ink);
  outline-offset: 4px;
  border-radius: 4px;
}

/* the pieces of a sentence that has just been left: they fade where they were */
.ghost {
  position: absolute;
  margin: 0;
  pointer-events: none;
}

/* ---------------------------------------------------------------- the pills */
.actions {
  position: relative;
  display: flex;
  flex: none;
  gap: 8px;
  margin-left: auto;
}

/* the elastic pill: with the pointer over it the label widens on the width axis and the pill swells with a bounce;
   pressed it squashes. The label at its widest keeps its place, so nothing around it moves */
.pill {
  --pb: transparent;
  --pt: var(--ink);
  --pline: inset 0 0 0 1px #d9d4cb;
  position: relative;
  display: inline-grid;
  place-items: center;
  height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 22px;
  background: none;
  color: var(--pt);
  font: inherit;
  font-size: 15px;
  letter-spacing: -0.005em;
  white-space: nowrap;
  cursor: pointer;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
}

.pill--main {
  --pb: var(--ink);
  --pt: #ffffff;
  --pline: none;
}

.pill__bg {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--pb);
  box-shadow: var(--pline);
  transition: inset 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pill__label {
  display: block;
  text-align: center;
  font-variation-settings: 'wght' 560, 'wdth' 92;
  transition: font-variation-settings 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* the label at its widest, unseen and zero high: it holds the place */
.pill__label::before {
  content: attr(data-text);
  display: block;
  height: 0;
  overflow: hidden;
  visibility: hidden;
  font-variation-settings: 'wght' 560, 'wdth' 116;
}

@media (hover: hover) and (pointer: fine) {
  .pill:hover .pill__bg {
    inset: -2px -6px;
  }

  .pill:hover .pill__label {
    font-variation-settings: 'wght' 560, 'wdth' 116;
  }
}

.pill:focus-visible {
  outline: none;
}

.pill:focus-visible .pill__bg {
  outline: 1.5px solid var(--ink);
  outline-offset: 3px;
}

/* ---------------------------------------------------------------- the small link left after the choice */
.reopen {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--gap) + env(safe-area-inset-bottom, 0px));
  z-index: 10;
  display: block;
  width: fit-content;
  margin: 0 auto;
  padding: 10px 14px;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  letter-spacing: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.reopen[hidden] {
  display: none;
}

.reopen__mask {
  position: relative;
  display: block;
  overflow: hidden;
  padding: 0.12em 0 0.1em;
}

.reopen__text {
  display: block;
  white-space: nowrap;
  font-variation-settings: 'wght' 520, 'wdth' 92;
  transition: font-variation-settings 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.reopen__state {
  color: var(--grey);
  font-variation-settings: 'wght' 380, 'wdth' 92;
  transition: font-variation-settings 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* the line the link comes out of, and goes back into */
.reopen__line {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 10px;
  height: 1px;
  background: var(--ink);
  transform: scaleX(0);
}

/* under the pointer the link breathes out on the width axis: it wants to open */
@media (hover: hover) and (pointer: fine) {
  .reopen:hover .reopen__text {
    font-variation-settings: 'wght' 600, 'wdth' 108;
  }

  .reopen:hover .reopen__state {
    font-variation-settings: 'wght' 420, 'wdth' 108;
  }
}

.reopen:focus-visible {
  outline: 1.5px solid var(--ink);
  outline-offset: 2px;
  border-radius: 8px;
}

/* the rings of the focus show for the keys, not after a finger or the mouse (the focus moves by itself when the
   banner closes and opens) */
html[data-using='pointer'] button.tok:focus-visible > .tok__lift,
html[data-using='pointer'] .pill:focus-visible .pill__bg,
html[data-using='pointer'] .reopen:focus-visible {
  outline: none;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- narrower: the pills under the sentence */
@media (max-width: 1080px) {
  .banner {
    --fs: clamp(19px, 2.6vw, 23px);
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
    padding: 20px 22px 18px;
  }

  .banner__frame {
    border-radius: 24px;
  }

  .actions {
    margin-left: 0;
  }

  .sentence {
    flex: 0 1 auto;
    flex-wrap: wrap;
    white-space: normal;
  }
}

@media (max-width: 560px) {
  .consent {
    --gap: max(12px, calc(50svh - 130px));
  }

  .banner {
    --fs: 21px;
    width: calc(100vw - 24px);
    max-width: none;
    padding: 20px 20px 16px;
  }

  .actions {
    width: 100%;
  }

  .actions .pill {
    flex: 1 1 0;
  }
}
