/* The index of places: one entry per name on show. See js/places.js.

   A double bezel on the foot row: an outer tray, an inner plate, and on it a
   toolbar of names in the eyebrow style. Wide windows get one centred row
   between the view controls; at 640px and narrower it is a list, a name to a
   row, at the foot, or in a column at the left on a phone held sideways. The
   index has no transform of its own, so the page's entrance may give it one. */

.index {
  --index-pad: 4px; /* the tray's lip */
  --index-entry: 32px; /* an entry's height: what a pointer can hit */
  --index-fade: 28px; /* how far the names fade out at an end with more to scroll to */
  --index-run: to right; /* the way the names run, and so the way they scroll */
  /* The house focus ring, turned inwards: the plate clips anything drawn outside
     an entry. Amber on the plate, linen inside it for the selected entry's fill. */
  --index-focus: inset 0 0 0 2px var(--amber-800), inset 0 0 0 4px var(--linen);
  position: absolute;
  z-index: 3;
  right: 0;
  bottom: var(--foot-row);
  left: 0;
  width: fit-content;
  /* Clear of the tour's button and the view controls, which keep off the
     safe-area insets (a notch on a phone held sideways) as well as the edge. */
  max-width: calc(100vw - 2 * (var(--edge) + var(--foot-side))
    - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  margin: 0 auto;
  touch-action: pan-x; /* a row may scroll sideways; a pinch here must never zoom the page */
}

.index[hidden],
[data-state="error"] .index,
[data-mode="edit"] .index {
  display: none;
}

.index__shell {
  padding: var(--index-pad);
  border-radius: var(--radius-shell-sm);
  background: var(--bezel-shell);
  box-shadow: var(--bezel-ring);
}

.index__core {
  overflow: hidden;
  border-radius: calc(var(--radius-shell-sm) - var(--index-pad));
  background: rgb(253 251 246 / 0.86); /* bone, as the house's fixed bars are */
  box-shadow: var(--bezel-core-shadow);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.index__list {
  position: relative; /* entries measure their place from here */
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2px 8px;
  padding: 3px;
  scrollbar-width: none;
  overscroll-behavior: contain;
}

.index__list::-webkit-scrollbar {
  display: none;
}

/* places.js measures the index the moment its layout changes, so nothing in it
   may ease from one layout to the next. Without this, the reduced-motion reset
   in base.css would give every property here a transition of 0.01ms. */
.index__list,
.index__group,
.index__entry {
  transition: none;
}

/* The public names, then the internal ones: a group goes onto a new line whole. */
.index__group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

/* Too many names for two lines: one line, scrolled sideways. */
.index[data-layout="scroll"] .index__list {
  flex-wrap: nowrap;
  justify-content: flex-start;
  overflow-x: auto;
}

.index[data-layout="scroll"] .index__group {
  flex: none;
  flex-wrap: nowrap;
}

.index__list[data-fade="end"] {
  -webkit-mask-image: linear-gradient(var(--index-run), #000 calc(100% - var(--index-fade)), transparent);
  mask-image: linear-gradient(var(--index-run), #000 calc(100% - var(--index-fade)), transparent);
}

.index__list[data-fade="start"] {
  -webkit-mask-image: linear-gradient(var(--index-run), transparent, #000 var(--index-fade));
  mask-image: linear-gradient(var(--index-run), transparent, #000 var(--index-fade));
}

.index__list[data-fade="both"] {
  -webkit-mask-image: linear-gradient(var(--index-run), transparent, #000 var(--index-fade),
    #000 calc(100% - var(--index-fade)), transparent);
  mask-image: linear-gradient(var(--index-run), transparent, #000 var(--index-fade),
    #000 calc(100% - var(--index-fade)), transparent);
}

/* ---- An entry ---------------------------------------------------------- */

.index__entry {
  position: relative;
  isolation: isolate; /* keeps the selected fill behind the name and in front of the plate */
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 8px;
  min-height: var(--index-entry);
  margin: 0;
  scroll-margin: var(--index-fade); /* an entry reached by the keyboard stops clear of the fade */
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink-70);
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* The key shared with the pins: a dot for a public name, a ring for an internal one. */
.index__entry::before {
  content: "";
  flex: none;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.index__entry--internal::before,
.index__mark::after {
  width: 7px;
  height: 7px;
  background: none;
  box-shadow: inset 0 0 0 1.5px currentColor;
}

/* The selected fill: laid in by opacity and scale, so the state is a shape as
   well as a colour. */
.index__entry::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  border-radius: inherit;
  background: var(--accent-deep);
  opacity: 0;
  transform: scale(0.9);
  transition: opacity var(--dur-2) var(--ease-estate), transform var(--dur-3) var(--ease-estate);
}

.index__entry[aria-current="true"] {
  color: var(--bone);
}

.index__entry[aria-current="true"]::after {
  opacity: 1;
  transform: scale(1);
}

.index__entry:focus-visible {
  outline: none;
  box-shadow: var(--index-focus);
}

/* Pointing at a name darkens it and draws a hairline under it from the left. */
.index__name {
  position: relative;
}

.index__name::after {
  content: "";
  position: absolute;
  right: 0.2em; /* the tracking after the last letter is not part of the word */
  bottom: -2px;
  left: 0;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: right center;
  transition: transform var(--dur-4) var(--ease-estate);
}

@media (hover: hover) {
  .index__entry:hover {
    color: var(--ink);
  }

  .index__entry[aria-current="true"]:hover {
    color: var(--bone);
  }

  .index__entry:hover .index__name::after {
    transform: scaleX(1);
    transform-origin: left center;
  }
}

/* How many places share the name, then which of them is selected ("1/2"). */
.index__count {
  margin-left: -2px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  opacity: 0.72;
}

/* What the ringed names are: said once ahead of them in a row, and on each of
   them in a list (.index__mark). */
.index__tag,
.index__mark {
  color: var(--terracotta-700);
  white-space: nowrap;
}

.index__tag {
  flex: none;
  padding: 0 4px 0 12px;
}

.index__mark {
  display: none;
}

/* ---- Narrow windows: a list, a name to a row --------------------------- */

@media (max-width: 640px) {
  .index {
    --index-entry: 44px;
    --index-run: to bottom;
    right: var(--edge);
    left: var(--edge);
    width: auto;
    max-width: none;
    margin: 0;
    touch-action: pan-y; /* the list may scroll up and down, and nothing else */
  }

  .index .index__list,
  .index .index__group {
    display: block;
  }

  /* Past this height the list scrolls inside itself. */
  .index .index__list {
    max-height: 46vh;
    max-height: min(46dvh, calc(100dvh - 420px)); /* a short phone keeps room for the model */
    padding: 0;
    overflow: hidden auto;
  }

  /* The tour's button sits above the list (controls.css), and the list gives
     up the room it takes, so the model keeps what it had. Never less than two
     rows. */
  body:has(.tour:not([hidden])) .index .index__list {
    max-height: max(calc(2 * var(--index-entry)), min(calc(46dvh - 60px), calc(100dvh - 480px)));
  }

  .index__entry {
    display: flex;
    width: 100%;
    padding: 0 14px;
    border-radius: 0;
    box-shadow: inset 0 -1px 0 rgb(20 18 14 / 0.1); /* the hairline between rows */
    text-align: left;
  }

  .index__group:last-child .index__entry:last-child {
    box-shadow: none;
  }

  /* In a list the name leads; what marks it follows at the right. */
  .index__entry::before,
  .index__tag {
    display: none;
  }

  .index__entry::after {
    inset: 4px 5px;
    border-radius: 10px;
  }

  .index__count {
    margin-left: auto;
  }

  .index__mark {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
  }

  .index__count + .index__mark {
    margin-left: 0;
  }

  .index__mark::after {
    content: "";
    flex: none;
    border-radius: 50%;
  }

  .index__entry[aria-current="true"] .index__mark {
    color: inherit;
  }
}

/* ---- A small phone on its side: a column at the left ------------------ */

/* 640px wide or less, and short: no height for the list at the foot, and no
   width for a row between the tour's button and the view controls. The tour's
   button (controls.css) and the list stand in a column at the left instead,
   under the wordmark, and ui.js fits the model beside it. The names keep the
   row's key: a dot or a ring before each, and "Internal" said once, ahead of
   the ringed ones. */
@media (max-width: 640px) and (max-height: 500px) and (orientation: landscape) {
  .index {
    --tour-pill: 42px; /* the tour's button: 36px in a 3px lip (controls.css) */
    top: calc(var(--column-top) + var(--tour-pill) + 10px); /* 10px under that button */
    right: auto;
    /* As tall as its list, down to the foot row at most: a short list leaves
       the map under the rest of the column to the visitor's hand. */
    bottom: auto;
    left: calc(var(--edge) + env(safe-area-inset-left, 0px));
    max-height: calc(100% - var(--column-top) - var(--tour-pill) - 10px - var(--foot-row));
    display: flex;
    flex-direction: column;
    width: max-content;
    max-width: min(240px, 42vw);
  }

  /* The list has the column's height, and scrolls inside it. */
  .index__shell,
  .index__core {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .index .index__list,
  body:has(.tour:not([hidden])) .index .index__list {
    min-height: 0;
    max-height: none;
  }

  .index__entry {
    padding: 0 12px;
    white-space: normal; /* a name too long for the column takes a second line */
  }

  .index__name {
    text-wrap: balance;
  }

  .index__entry::before,
  .index__tag {
    display: block;
  }

  .index__tag {
    padding: 12px 12px 4px;
  }

  .index__mark {
    display: none;
  }
}

@media (max-width: 640px) and (max-height: 500px) and (orientation: landscape) and (pointer: coarse) {
  .index {
    --tour-pill: 50px; /* 44px on a touch screen */
  }
}

/* A finger needs the taller entry whatever the window's width. */
@media (pointer: coarse) {
  .index {
    --index-entry: 44px;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .index__core {
    background: var(--bone);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
