/* == map-image 0.5.0, parisiam/patterns@ef3e4dc == */
/*
 * map-image: a map image of a real place, shown at its own size in a box of the site's size, with a card laid
 * over it: « Open in Maps », the directions and the place's name and address, by what the box has room for.
 * Contract, options and pitfalls: README.md, beside this file.
 */

/* Settings: the card's colours, by the style of the map's image. The site changes them on the root, for every
   map, for one page's or for one map, data-xps-map-image="<name>". The box's size is the site's: this height only
   keeps it from collapsing. */
:where(.xps-map-image) {
  --xps-map-image-land: #F2EFE9;
  --xps-map-image-surface: #FFFFFF;
  --xps-map-image-text: #1F1F1F;
  --xps-map-image-muted: #5F6368;
  --xps-map-image-link: #3C4043;
  --xps-map-image-accent: #1A73E8;
  --xps-map-image-on-accent: #FFFFFF;
  --xps-map-image-route-background: #F1F3F4;
  --xps-map-image-shadow: rgb(0 0 0 / 0.3);
  --xps-map-image-credit: #333333;
  --xps-map-image-credit-background: rgb(255 255 255 / 0.75);
  block-size: 20rem;
}
:where(.xps-map-image[data-xps-map-image-style="gray"]) {
  --xps-map-image-land: #EDEDED;
  --xps-map-image-accent: #3C4043;
}
/* The dark colours: a dark image alone, or the dark image of a map that has one while the page is dark. The page
   is dark by the theme pattern's dark class once its script has marked <html> with data-xps-theme, or else by
   the device, below: a page whose script did not run follows the device. */
:where(.xps-map-image[data-xps-map-image-style$="-dark"],
       :root[data-xps-theme].dark .xps-map-image[data-xps-map-image-dark]) {
  --xps-map-image-land: #2B2B2B;
  --xps-map-image-surface: #202124;
  --xps-map-image-text: #E8EAED;
  --xps-map-image-muted: #9AA0A6;
  --xps-map-image-link: #E8EAED;
  --xps-map-image-accent: #8AB4F8;
  --xps-map-image-on-accent: #202124;
  --xps-map-image-route-background: #3C4043;
  --xps-map-image-shadow: rgb(0 0 0 / 0.6);
  --xps-map-image-credit: #BDC1C6;
  --xps-map-image-credit-background: rgb(32 33 36 / 0.75);
}
:where(.xps-map-image[data-xps-map-image-style="gray-dark"],
       :root[data-xps-theme].dark .xps-map-image[data-xps-map-image-dark="gray-dark"]) {
  --xps-map-image-accent: #DADCE0;
}
@media (prefers-color-scheme: dark) {
  :where(:root:not([data-xps-theme]) .xps-map-image[data-xps-map-image-dark]) {
    --xps-map-image-land: #2B2B2B;
    --xps-map-image-surface: #202124;
    --xps-map-image-text: #E8EAED;
    --xps-map-image-muted: #9AA0A6;
    --xps-map-image-link: #E8EAED;
    --xps-map-image-accent: #8AB4F8;
    --xps-map-image-on-accent: #202124;
    --xps-map-image-route-background: #3C4043;
    --xps-map-image-shadow: rgb(0 0 0 / 0.6);
    --xps-map-image-credit: #BDC1C6;
    --xps-map-image-credit-background: rgb(32 33 36 / 0.75);
  }
  :where(:root:not([data-xps-theme]) .xps-map-image[data-xps-map-image-dark="gray-dark"]) {
    --xps-map-image-accent: #DADCE0;
  }
}

/* The box and its image: the image at its own size, its width descriptor over its sizes, centred, never scaled, so
   that a larger box shows more of the neighbourhood at the same scale, as an embed would. The box is the
   container the card's modes query, and a stacking context, so that the card's layers never meet the page's. */
.xps-map-image {
  position: relative;
  overflow: hidden;
  container-type: size;
  isolation: isolate;
  background: var(--xps-map-image-land);
}
.xps-map-image img {
  position: absolute;
  top: 50%;
  left: 50%;
  width: auto;
  height: auto;
  max-width: none;
  margin: 0;
  translate: -50% -50%;
}
/* A map with a dark image holds two <img>, the light one and the dark one, and shows the one the page's colours
   call for, by the same conditions as the dark colours: a <source media> follows the device only, never the
   theme's switch. The hidden one, lazy, is not downloaded. Each <img> may sit in a <picture> that gives it the
   phone image: hiding the <img> is enough, the <picture> shows nothing of its own. */
.xps-map-image .xps-map-image-dark-image {
  display: none;
}
:root[data-xps-theme].dark .xps-map-image[data-xps-map-image-dark] .xps-map-image-light-image {
  display: none;
}
:root[data-xps-theme].dark .xps-map-image[data-xps-map-image-dark] .xps-map-image-dark-image {
  display: block;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-xps-theme]) .xps-map-image[data-xps-map-image-dark] .xps-map-image-light-image {
    display: none;
  }
  :root:not([data-xps-theme]) .xps-map-image[data-xps-map-image-dark] .xps-map-image-dark-image {
    display: block;
  }
}

.xps-map-image .xps-map-image-credit {
  position: absolute;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 0 4px;
  background: var(--xps-map-image-credit-background);
  color: var(--xps-map-image-credit);
  font-size: 0.625rem;
  line-height: 1.5;
  white-space: nowrap;
}
.xps-map-image .xps-map-image-credit a {
  color: inherit;
  text-decoration: none;
}
.xps-map-image .xps-map-image-credit a:hover {
  text-decoration: underline;
}

/* The card holds everything; the box's size decides what it shows */
.xps-map-image .xps-map-image-card {
  position: absolute;
  top: 8px;
  left: 8px;
  max-width: calc(100% - 16px);
  box-sizing: border-box;
  margin: 0;
  padding: 8px 12px;
  background: var(--xps-map-image-surface);
  border-radius: 2px;
  box-shadow: 0 1px 4px var(--xps-map-image-shadow);
  color: var(--xps-map-image-text);
  font-size: 1rem;
  line-height: 1.4;
  text-align: left;
}
.xps-map-image .xps-map-image-name,
.xps-map-image .xps-map-image-address {
  display: none;
  margin: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.xps-map-image .xps-map-image-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.xps-map-image .xps-map-image-open,
.xps-map-image .xps-map-image-route {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.xps-map-image .xps-map-image-open svg,
.xps-map-image .xps-map-image-route svg {
  flex: none;
  fill: currentColor;
}
.xps-map-image .xps-map-image-open:focus-visible,
.xps-map-image .xps-map-image-route:focus-visible {
  outline: 2px solid var(--xps-map-image-accent);
  outline-offset: 2px;
}
.xps-map-image .xps-map-image-route {
  display: none;
}
/* « Open in Maps » in its long text, or its short one in a narrow box: the short one, hidden from screen readers,
   is words of the long one, which they always read, so that the visible label stays in the link's name */
.xps-map-image .xps-map-image-open-short {
  display: none;
}

/* Mode link, in any box: « Open in Maps ↗ », a link */
.xps-map-image .xps-map-image-open {
  gap: 6px;
  min-height: 24px;
  color: var(--xps-map-image-link);
  font-weight: 600;
  font-size: 0.875rem;
}
.xps-map-image .xps-map-image-open svg {
  order: 1;
  width: 18px;
  height: 18px;
}
.xps-map-image .xps-map-image-open:hover span {
  text-decoration: underline;
}

/* Mode buttons, from 170 × 120, unless data-xps-map-image-card="link": the « Open in Maps » button and the
   directions button. The pin is 30 px below the box's centre: a mode shows once its card fits above the pin, or
   beside it in the box's left half */
@container (min-width: 170px) and (min-height: 120px) {
  .xps-map-image:not([data-xps-map-image-card="link"]) .xps-map-image-card {
    padding: 8px;
  }
  .xps-map-image:not([data-xps-map-image-card="link"]) .xps-map-image-open {
    padding: 6px 14px 6px 10px;
    border-radius: 999px;
    background: var(--xps-map-image-accent);
    color: var(--xps-map-image-on-accent);
    font-weight: 500;
    font-size: 0.8125rem;
  }
  .xps-map-image:not([data-xps-map-image-card="link"]) .xps-map-image-open svg {
    order: 0;
  }
  .xps-map-image:not([data-xps-map-image-card="link"]) .xps-map-image-open:hover {
    filter: brightness(1.08);
  }
  .xps-map-image:not([data-xps-map-image-card="link"]) .xps-map-image-open:hover span {
    text-decoration: none;
  }
  .xps-map-image:not([data-xps-map-image-card="link"]) .xps-map-image-route {
    display: inline-flex;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--xps-map-image-route-background);
    color: var(--xps-map-image-accent);
  }
  .xps-map-image:not([data-xps-map-image-card="link"]) .xps-map-image-route svg {
    width: 20px;
    height: 20px;
  }
  .xps-map-image:not([data-xps-map-image-card="link"]) .xps-map-image-route:hover {
    filter: brightness(0.95);
  }
}
/* Under 240 px wide, the button shows the short text */
@container (min-width: 170px) and (min-height: 120px) and (max-width: 239.98px) {
  .xps-map-image:not([data-xps-map-image-card="link"]) .xps-map-image-open-long {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .xps-map-image:not([data-xps-map-image-card="link"]) .xps-map-image-open-short {
    display: inline;
  }
}

/* Mode full, from 300 × 240 or from 600 × 140, unless data-xps-map-image-card="link" or "buttons": the name, the
   address and the buttons */
@container ((min-width: 300px) and (min-height: 240px)) or ((min-width: 600px) and (min-height: 140px)) {
  .xps-map-image:not([data-xps-map-image-card="link"], [data-xps-map-image-card="buttons"]) .xps-map-image-card {
    display: grid;
    gap: 2px;
    padding: 10px 12px;
  }
  .xps-map-image:not([data-xps-map-image-card="link"], [data-xps-map-image-card="buttons"]) .xps-map-image-name {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
  }
  .xps-map-image:not([data-xps-map-image-card="link"], [data-xps-map-image-card="buttons"]) .xps-map-image-address {
    display: block;
    color: var(--xps-map-image-muted);
    font-size: 0.75rem;
  }
  .xps-map-image:not([data-xps-map-image-card="link"], [data-xps-map-image-card="buttons"]) .xps-map-image-actions {
    margin-top: 6px;
  }
}
/* Under 240 px high, the card stays in the box's left half, clear of the pin */
@container (min-width: 600px) and (min-height: 140px) and (max-height: 239.98px) {
  .xps-map-image:not([data-xps-map-image-card="link"], [data-xps-map-image-card="buttons"]) .xps-map-image-card {
    max-width: calc(50cqw - 20px);
  }
}

/* Narrow boxes: the link shows the short text under 200 px wide */
@container (max-width: 199.98px) {
  .xps-map-image .xps-map-image-open-long {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .xps-map-image .xps-map-image-open-short {
    display: inline;
  }
}
/* « ESA WorldCover » shortened to « ESA » under 300 px wide */
@container (max-width: 299.98px) {
  .xps-map-image .xps-map-image-credit-long {
    display: none;
  }
}
/* == end of map-image == */
