/* Share, in the footer: a text button, and a menu of app-icon tiles that floats above it (it never grows the page). In SÈRAI's black and white. */
.share {
  --share-ink: #000000;
  --share-line: #c8c8c8;
  --share-ease: cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  display: grid;
  justify-items: end;
}

.share[hidden] {
  display: none;
}

.share__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  background: none;
  color: var(--share-ink);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* The menu: the row of tiles and its padding, nothing else. The name label (above a tile) and the pill (above the labels) are absolute, so they take no room. */
.share__menu {
  --tile: 52px; /* six tiles, 5 px gaps and 8 px padding make a 355 px menu: it fits the 358 px sheet body from 390 px wide. Below that: two rows of three. */
  --gap: 5px;
  /* Sheen on every tile, on the tile only, never on a logo (Kelvin asked for a gradient iOS feel). Same hue, white 18 percent at the top fading to 0.
     To turn it off on the brand tiles, set this to none. */
  --brand-sheen: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0));
  position: absolute;
  inset: auto 0 calc(100% + 4px) auto;
  z-index: 2;
  width: max-content;
  padding: 8px;
  border: 1px solid var(--share-line);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 10px 28px -8px rgba(0, 0, 0, 0.28);
  transform-origin: 100% 100%;
  scroll-margin: 70px 0 0; /* scrollIntoView leaves room above for the label and the pill */
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 150ms var(--share-ease), transform 150ms var(--share-ease);
}

.share__menu[hidden] {
  display: none;
}

.share__menu.is-down {
  inset: calc(100% + 4px) 0 auto auto;
  transform-origin: 100% 0;
  scroll-margin: 0 0 44px; /* room below for the labels */
}

.share__menu.is-open {
  opacity: 1;
  transform: none;
  transition-duration: 200ms;
}

.share__list {
  display: grid;
  grid-template-columns: repeat(6, var(--tile));
  gap: var(--gap);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* The tiles rise 5 px and fade in, 25 ms apart; the last one is done 275 ms after the open starts. */
.share__list li {
  position: relative;
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 150ms var(--share-ease), transform 150ms var(--share-ease);
}

.share__menu.is-open .share__list li {
  opacity: 1;
  transform: none;
  transition-duration: 150ms;
}

.share__menu.is-open .share__list li:nth-child(2) { transition-delay: 25ms; }
.share__menu.is-open .share__list li:nth-child(3) { transition-delay: 50ms; }
.share__menu.is-open .share__list li:nth-child(4) { transition-delay: 75ms; }
.share__menu.is-open .share__list li:nth-child(5) { transition-delay: 100ms; }
.share__menu.is-open .share__list li:nth-child(6) { transition-delay: 125ms; }

/* An app-icon tile: a rounded square with a tight and a soft shadow. The logo is about 55 percent of it. The shadow and the sheen are on the tile, never on the logo. */
.share__item {
  display: grid;
  place-items: center;
  width: var(--tile);
  height: var(--tile);
  padding: 0;
  border: 0;
  border-radius: 23%;
  background-color: #e8e8ec;
  background-image: linear-gradient(180deg, #fbfbfd, #e1e1e6);
  color: var(--share-ink);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12), 0 5px 10px -3px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms var(--share-ease), box-shadow 120ms var(--share-ease);
}

/* The brand tiles: brand colour with the sheen, an approved white logo on top. Pinterest: a white tile with the neutral sheen and its red badge on a white disc. */
.share__item--whatsapp { background-color: #25d366; background-image: var(--brand-sheen); color: #ffffff; }
.share__item--facebook { background-color: #0866ff; background-image: var(--brand-sheen); color: #ffffff; }
.share__item--x { background-color: #000000; background-image: var(--brand-sheen); color: #ffffff; }
.share__item--pinterest { background-color: #ffffff; background-image: linear-gradient(180deg, #ffffff, #ececf0); box-shadow: inset 0 0 0 1px #d9dbe0, 0 1px 1px rgba(0, 0, 0, 0.12), 0 5px 10px -3px rgba(0, 0, 0, 0.22); }

.share__item svg {
  display: block;
  width: 55%;
  height: 55%;
  overflow: visible; /* the Pinterest path reaches a hair past its viewBox; Chromium would clip the badge flat */
}

/* Keyboard focus: a dark ring outside the tile with a 2 px gap of the white menu, so it reads against the white menu and, through the gap, never sits on the tile or the logo. */
.share__item:focus-visible { outline: 2px solid var(--share-ink); outline-offset: 2px; }

/* The press answers on pointer down. */
.share__item:active {
  transform: scale(0.94);
  transition-duration: 80ms;
}

/* The name of a tile, a small card above it. Shown on hover (a fine pointer) and on keyboard focus. It is part of its tile's list item,
   so the pointer can move onto it without it going (WCAG 1.4.13); Escape closes the menu and with it the label. */
.share__label {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  z-index: 3;
  padding: 7px 10px;
  border: 1px solid var(--share-line);
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.3);
  color: var(--share-ink);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  --lx: -50%; /* sideways centring, kept under reduced motion */
  --ly: 3px;  /* the small rise, removed under reduced motion */
  transform: translate(var(--lx), var(--ly));
  transition: opacity 120ms var(--share-ease), transform 120ms var(--share-ease), visibility 0s 120ms;
}

/* The first and last label line up with their tile's edge, so none runs past the menu. */
.share__list li:first-child .share__label { left: 0; --lx: 0px; }
.share__list li:last-child .share__label { left: auto; right: 0; --lx: 0px; }

/* A bridge over the gap, so moving from the tile to its label does not lose the hover. */
.share__label::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 8px;
}

.share__list li:has(.share__item:focus-visible) .share__label {
  opacity: 1;
  visibility: visible;
  --ly: 0px;
  transition-delay: 0s;
}

/* With the menu below Share, labels go under their tiles and the pill under the menu. */
.share__menu.is-down .share__label { bottom: auto; top: calc(100% + 6px); }
.share__menu.is-down .share__label::after { top: auto; bottom: 100%; }

/* "Link copied": a pill above the labels that fades and rises in, stays about 1.5 s, and fades out. It stays a status for assistive technology. */
.share__status {
  position: absolute;
  right: 0;
  bottom: calc(100% + 38px);
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--share-ink);
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.4);
  color: #ffffff;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 160ms var(--share-ease), transform 160ms var(--share-ease);
}

.share__status.is-on {
  opacity: 1;
  transform: none;
}

.share__menu.is-down .share__status { bottom: auto; top: calc(100% + 38px); transform: translateY(-6px); }
.share__menu.is-down .share__status.is-on { transform: none; }

@media (min-width: 700px) {
  .share__menu {
    --tile: 56px;
    --gap: 8px;
  }
}

/* Under 390 px six 52 px tiles cannot share one row: two rows of three. */
@media (max-width: 389px) {
  .share__list { grid-template-columns: repeat(3, var(--tile)); }
  .share__list li { position: static; }
  /* Labels sit above the whole menu here, so a label never covers a tile of the other row. A label lines up with its column: the left edge for column 1, the right edge for column 3, centred for column 2, so none runs past the menu. */
  .share__list .share__label,
  .share__list li:first-child .share__label,
  .share__list li:last-child .share__label { bottom: calc(100% + 6px); left: 50%; right: auto; --lx: -50%; }
  .share__list li:nth-child(3n + 1) .share__label { left: 0; --lx: 0px; }
  .share__list li:nth-child(3n) .share__label { left: auto; right: 0; --lx: 0px; }
  .share__menu.is-down .share__list .share__label { bottom: auto; top: calc(100% + 6px); }
}

@media (hover: hover) and (pointer: fine) {
  .share__btn:hover { text-decoration: underline; text-underline-offset: 3px; }
  .share__item:hover { transform: translateY(-2px); box-shadow: 0 2px 2px rgba(0, 0, 0, 0.12), 0 9px 16px -4px rgba(0, 0, 0, 0.26); }
  .share__item--pinterest:hover { box-shadow: inset 0 0 0 1px #d9dbe0, 0 2px 2px rgba(0, 0, 0, 0.12), 0 9px 16px -4px rgba(0, 0, 0, 0.26); }
  .share__item:hover:active { transform: scale(0.94); }
  .share__list li:hover .share__label {
    opacity: 1;
    visibility: visible;
    --ly: 0px;
    transition-delay: 0s;
  }
  /* One label at a time: while the pointer is on a tile, the label of a tile that only has keyboard focus steps aside, so two labels never overlap. It returns when the pointer leaves. The focus ring stays. */
  .share__list:has(li:hover) li:not(:hover) .share__label {
    opacity: 0;
    visibility: hidden;
    transition-delay: 0s, 0s, 0s;
  }
}

/* Reduced motion: no movement or scale, short fades only. */
@media (prefers-reduced-motion: reduce) {
  .share__menu,
  .share__menu.is-open,
  .share__list li,
  .share__menu.is-open .share__list li,
  .share__status {
    transform: none !important;
    transition-property: opacity;
    transition-duration: 100ms;
    transition-delay: 0s;
  }
  /* The label keeps its sideways centring and loses only the rise. */
  .share__label { --ly: 0px !important; transition-property: opacity; transition-duration: 100ms; transition-delay: 0s; }
  .share__item,
  .share__item:hover,
  .share__item:active,
  .share__item:hover:active { transform: none; transition-property: box-shadow; }
}
