/* AEKE .sg — the "See More on Instagram" strip.
 *
 * MEASURED AGAINST THE LIVE SITE (1440, and again at 768 and 375):
 *
 *   page gutter          50px each side at 768 and up, 15px below
 *   grid                 6 columns, `gap: 0.1667%` — 2.208px at a 1325px container
 *   tile                 219 x 274, which is 4:5
 *   heading              42/50 at 1440, 36/44 at 768, 28/36 at 375
 *   hover layer          hidden at rest (`opacity: 0`), a dark scrim plus a badge on hover
 *   tile links           none. The twelve tiles are not anchors at all.
 *
 * ## The one deliberate divergence
 *
 * The live plugin pins every tile at a **fixed 219px** at all three widths, so six columns
 * need 1314px of container and the strip only fits above roughly 1420px. At 768 it is
 * 1314 inside 668 and at 375 it is 1314 inside 345 — the row runs off its own container
 * and the later tiles are simply not reachable.
 *
 * Ours is fluid. At 1440 that resolves to 219px, so the wide rendering is identical, and
 * on narrower screens the same six columns shrink instead of being cut off. Below 768 it
 * drops to three columns so a tile is still a usable size rather than a 57px sliver.
 * Reproduced deliberately rather than silently — same rule as the two header quirks.
 */

.instagram-feed {
  max-width: var(--grid-width-row);
  margin-right: auto;
  margin-left: auto;
  padding: 0 15px;
}

/* A block formatting context, for the same reason `.rich-text-section` is one: the live
   section measures 770 around a 630px app-wrapper, and the 140px difference is its own
   70px top and bottom margins being *contained* rather than collapsing out into the
   neighbouring sections. Without this the section measures 617 and the spacing is wrong
   by exactly those 140px. */
.instagram-feed-section {
  display: flow-root;
}

@media (min-width: 48em) {
  .instagram-feed {
    padding: 0 50px;
  }
}

.instagram-feed__heading {
  margin: 0 0 20px;
}

.instagram-feed--inner {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.1667%;
}

@media (min-width: 48em) {
  .instagram-feed--inner {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* A `<button>`, so it needs its chrome removed. It is the control that opens the popup,
   which is the only reason it is a button at all — upstream's tiles are `<div>`s with a
   listener, unreachable by keyboard and with no accessible name. */
.instagram-feed--item {
  position: relative;
  display: block;
  width: 100%;
  overflow: hidden;
  aspect-ratio: 4 / 5;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.instagram-feed--item:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.instagram-feed--item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* The scrim and the badge. Live keeps both at `opacity: 0` until hover — so the strip at
   rest is twelve bare images, and the badge only says "this one is a video" once the
   pointer is already on the tile.
 *
 * That is a real affordance buried behind a pointer, and it is also why the tiles carry
 * no `alt`: there is nothing to describe beyond the section heading. Both layers are
 * `aria-hidden` because neither is content — one is a decoration, the other is a hint
 * about a pointer that a screen reader does not have. */
.instagram-feed--item-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(var(--color-overlay-rgb), 0.4);
  opacity: 0;
  transition: opacity var(--duration-theme) var(--ease-theme);
}

.instagram-feed--item:hover .instagram-feed--item-overlay,
.instagram-feed--item:focus-within .instagram-feed--item-overlay {
  opacity: 1;
}

.instagram-feed--item-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: var(--color-heading);
}

.instagram-feed--item-badge svg {
  width: 100%;
  height: 100%;
}

/* A touch device has no hover, so the badge would never appear. Show it at rest there —
   the same information, without asking for a pointer that does not exist. */
@media (hover: none) {
  .instagram-feed--item-overlay {
    background: none;
    opacity: 1;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 8px;
  }

  .instagram-feed--item-overlay::before {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(var(--color-overlay-rgb), 0.35);
  }
}

@media (prefers-reduced-motion: reduce) {
  .instagram-feed--item-overlay {
    transition: none;
  }
}

/* ------------------------------------------------------------------ the popup
 *
 * MEASURED AGAINST THE LIVE SITE:
 *
 *   scrim      rgba(0,0,0,.8), `position: fixed`, above everything
 *   dialog     90% x 90%, white, border-radius 15px, flex row
 *   media      `flex: 0 1 auto`; the video is `height: 100%` with `object-fit: contain`
 *   details    a fixed 500px column
 *   avatar     45 x 45, fully round
 *   account    15px / 600
 *   caption    15px / `white-space: pre-wrap`
 *   date       11px, 3px above it
 *   close      30 x 30, 24px from the right, 17px from the top
 *   arrows     32 x 32, 15px in from the edge, `--color-body`
 *
 * Two greys are expressed as a fraction of the overlay colour rather than as new tokens:
 * the caption is 60% black (which is #666, the measured value) and the header rule is 8%
 * black. Both are strictly-relative shades of black and adding near-duplicate greys to the
 * token set would make it harder to read, not easier.
 */

.instagram-feed__overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(var(--color-overlay-rgb), 0.8);
}

/* `hidden` has to beat the `display: flex` above. */
.instagram-feed__overlay[hidden] {
  display: none;
}

/* Scroll lock while the popup is open, so the page behind it does not move. */
body.instagram-is-open {
  overflow: hidden;
}

.instagram-feed__dialog {
  display: flex;
  flex-direction: row;
  max-width: 90%;
  height: 90%;
  overflow: hidden;
  border-radius: 15px;
  background: var(--surface-tile-light);
}

.instagram-feed__dialog[hidden] {
  display: none;
}

.instagram-feed__media {
  position: relative;
  display: flex;
  flex: 0 1 auto;
  min-width: 0;
}

.instagram-feed__media video,
.instagram-feed__media img {
  display: block;
  width: auto;
  height: 100%;
  object-fit: contain;
}

.instagram-feed__description {
  display: flex;
  flex: 0 1 auto;
  flex-direction: column;
  width: 500px;
  max-width: 100%;
  padding: 20px;
  overflow: hidden;
}

.instagram-feed__header {
  display: flex;
  align-items: center;
  gap: 12px;
  /* 8% black — the live rule is #eee, which is exactly that on a white panel. */
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(var(--color-overlay-rgb), 0.08);
}

.instagram-feed__avatar {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  object-fit: cover;
}

.instagram-feed__account {
  font-size: 0.9375rem; /* 15px */
  font-weight: 600;
  color: var(--color-ink);
  text-decoration: none;
}

.instagram-feed__account:hover {
  text-decoration: underline;
}

.instagram-feed__caption {
  /* The caption is the only part that can be any length, so it is the part that scrolls. */
  flex: 1 1 auto;
  margin-top: 16px;
  overflow-y: auto;
  font-size: 0.9375rem;
  color: rgba(var(--color-overlay-rgb), 0.6);
  white-space: pre-wrap;
}

.instagram-feed__date {
  padding-top: 3px;
  font-size: 0.6875rem; /* 11px */
  color: rgba(var(--color-overlay-rgb), 0.6);
}

.instagram-feed__close,
.instagram-feed__arrow {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.instagram-feed__close {
  top: 17px;
  right: 24px;
  width: 30px;
  height: 30px;
  color: var(--color-heading);
}

.instagram-feed__close svg {
  width: 24px;
  height: 24px;
}

.instagram-feed__arrow {
  top: 50%;
  width: 32px;
  height: 32px;
  color: var(--color-body);
  transform: translateY(-50%);
}

.instagram-feed__arrow--prev {
  left: 15px;
}

.instagram-feed__arrow--next {
  right: 15px;
}

.instagram-feed__arrow svg {
  width: 20px;
  height: 20px;
}

.instagram-feed__close:focus-visible,
.instagram-feed__arrow:focus-visible,
.instagram-feed__video-button:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Play/pause and mute. Upstream places these over the media; the position is not
   measurable from the closed state, so they sit bottom-left under a soft scrim — the
   conventional spot, and legible over both light and dark artwork. */
.instagram-feed__video-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  display: flex;
  gap: 4px;
  padding: 10px;
}

.instagram-feed__video-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(var(--color-overlay-rgb), 0.5);
  color: var(--color-heading);
  cursor: pointer;
}

.instagram-feed__video-button svg {
  width: 16px;
  height: 16px;
}

/* Both glyphs ship; the pressed state picks one. The alternative is rewriting the button's
   markup on every toggle, which puts state in the DOM twice. */
.instagram-feed__icon-play,
.instagram-feed__icon-pause,
.instagram-feed__icon-muted,
.instagram-feed__icon-sound {
  display: none;
}

[data-instagram-play][aria-pressed="false"] .instagram-feed__icon-play,
[data-instagram-play][aria-pressed="true"] .instagram-feed__icon-pause,
[data-instagram-mute][aria-pressed="true"] .instagram-feed__icon-muted,
[data-instagram-mute][aria-pressed="false"] .instagram-feed__icon-sound {
  display: block;
}

/* Below 768 the dialog stacks: the details go under the media rather than beside it, and
   the caption stops scrolling so the whole thing is one column. */
@media (max-width: 47.99em) {
  .instagram-feed__dialog {
    flex-direction: column;
    max-width: 94%;
    height: auto;
    max-height: 90%;
  }

  .instagram-feed__media {
    flex: 1 1 auto;
    min-height: 0;
  }

  .instagram-feed__description {
    width: auto;
    max-height: 45vh;
  }

  .instagram-feed__arrow {
    display: none;
  }
}
