/* Troy landing: the connection picture (#food-map), beside the phone in "A day at USC".
   No streets and no buildings: the person asking is one circle ("you"), the person or people Troy finds are
   another circle or a small cluster, and a gold line draws between them when they are connected, with one small
   fact on it.
   One layer per stop (g.map-layer[data-layer]). map.js sets data-stop on #food-map (which layer shows) and
   data-phase on each layer (how far its story has got). Inside a layer, data-at="1" marks what appears when Troy
   finds the other side, and data-at="2" what appears when they are connected.
   With no attributes at all (no JavaScript, reduced motion) this is the finished free food picture.
   Only opacity and transform move, plus stroke-dashoffset on the gold lines. */

#food-map { padding: 0; aspect-ratio: 4 / 3; }
#food-map .map {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Words */
.map text {
  font-family: var(--font-sans);
  text-anchor: middle;
}
.map-you text { font-size: 15px; font-weight: 600; fill: var(--white); }
.map-in { font-size: 15px; font-weight: 600; fill: var(--ink); }
.map-name { font-size: 14px; font-weight: 500; fill: var(--ink); }
.map-place { font-size: 13.5px; font-weight: 500; fill: var(--stone); }
.map-fact { font-size: 14px; font-weight: 600; fill: var(--ink); }
.map-range-label {
  paint-order: stroke;
  stroke: var(--paper);
  stroke-width: 8px;
  stroke-linejoin: round;
}

/* Circles */
.map-you circle { fill: var(--ink); }
.map-other { fill: var(--white); stroke: var(--line); stroke-width: 1.5; }
.map-who { fill: var(--stone); }
.map-peer { fill: var(--gold); stroke: var(--ink); stroke-width: 1; }
.map-dot-off { fill: var(--stone); opacity: 0.4; }
.map-dot-on { fill: var(--gold); stroke: var(--ink); stroke-width: 1; }

/* The gold line, on an amber one so it reads on paper */
.map-link,
.map-link-shade {
  fill: none;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 0;
}
.map-link { stroke: var(--gold); stroke-width: 3.5; }
.map-link-shade { stroke: var(--amber); stroke-width: 5.5; }
.map-arrow {
  fill: none;
  stroke: var(--amber);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The 15-minute walk */
.map-range {
  fill: rgba(var(--ink-rgb), 0.03);
  stroke: var(--stone);
  stroke-opacity: 0.45;
  stroke-width: 1.25;
  vector-effect: non-scaling-stroke;
  transform-box: fill-box;
  transform-origin: center;
}

/* ---------- Which layer shows ---------- */

/* Not the pinned scene: the finished free food picture only. */
html:not(.day-on) #food-map .map-layer:not([data-layer="food"]) { display: none; }

/* The pinned scene: every layer is hidden by default, before map.js has said anything, and only the current
   stop's layer shows. A layer that is not current is gone at once (visibility is not animated), so two pictures
   are never on top of one another. */
html.day-on #food-map .map-layer { opacity: 0; visibility: hidden; }
#food-map[data-stop] .map-layer { opacity: 0; }
#food-map[data-stop="lost-found"] .map-layer[data-layer="lost-found"],
#food-map[data-stop="concern"] .map-layer[data-layer="concern"],
#food-map[data-stop="food"] .map-layer[data-layer="food"],
#food-map[data-stop="broken"] .map-layer[data-layer="broken"],
#food-map[data-stop="rides"] .map-layer[data-layer="rides"] { opacity: 1; visibility: visible; }

/* ---------- How far a layer's story has got ---------- */

.map-pop,
.map-move { transform-box: fill-box; transform-origin: center; }

/* Not yet: hidden. Circles wait small, the cluster waits where it comes from, gold lines wait undrawn. */
:is(.map-layer[data-phase="0"] [data-at],
    .map-layer[data-phase="1"] [data-at="2"]) { opacity: 0; }
:is(.map-layer[data-phase="0"] [data-at],
    .map-layer[data-phase="1"] [data-at="2"]).map-pop { transform: scale(0.6); }
:is(.map-layer[data-phase="0"] [data-at],
    .map-layer[data-phase="1"] [data-at="2"]).map-move { transform: translate(var(--dx, 0px), var(--dy, 0px)); }
:is(.map-layer[data-phase="0"] [data-at],
    .map-layer[data-phase="1"] [data-at="2"]):is(.map-link, .map-link-shade) { stroke-dashoffset: 100; }

@media (prefers-reduced-motion: no-preference) {
  .map-layer { transition: opacity 0.45s ease; }
  .map-layer [data-at] {
    transition: opacity 0.4s ease, transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
    transition-delay: calc(var(--i, 0) * 110ms);
  }
  .map-layer :is(.map-link, .map-link-shade)[data-at] {
    transition: opacity 0.2s ease, stroke-dashoffset 0.9s ease;
    transition-delay: calc(0.1s + var(--i, 0) * 0.55s);
  }
  .map-layer :is(.map-fact, .map-arrow)[data-at] { transition-delay: calc(0.75s + var(--i, 0) * 0.55s); }

  /* Free food. Waiting: */
  #food-map.is-armed:not(.is-playing) .map-layer[data-layer="food"] :is(.map-range, .map-range-label, .map-dot-on, .map-count) { opacity: 0; }
  /* The ring spreads, then the circles inside it light up one by one. */
  #food-map.is-playing .map-range { animation: map-spread 1s cubic-bezier(0.2, 0.6, 0.3, 1) both; }
  #food-map.is-playing .map-range-label { animation: map-fade 0.3s ease-out 0.8s both; }
  #food-map.is-playing .map-count { animation: map-fade 0.3s ease-out 1s both; }
  #food-map.is-playing .map-dot-on {
    animation: map-light 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both;
    animation-delay: calc(1s + var(--i) * 0.15s);
    transform-box: fill-box;
    transform-origin: center;
  }
}

@keyframes map-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes map-light {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: none; }
}
@keyframes map-spread {
  from { opacity: 0; transform: scale(0); }
  20% { opacity: 1; }
  to { opacity: 1; transform: scale(1); }
}
