/*
 * Home US map (site/snippets/blocks/locationmap.php, docs/design/motion.md
 * "map"). Linked by the block itself, so only a page with the map loads it.
 * Static styles sit in the "blocks" layer, the motion in the "motion" layer
 * (both declared in tokens.css), under the effect key "map".
 *
 * - Without JS (.hm without .is-tabbed): every tier shows on the map and
 *   the three descriptions are a list. home-map.js adds .is-tabbed: one
 *   tier (.is-active) and its panel.
 * - Tier colors are fills only. Every marker, arc and lens has an ink
 *   outline (ink on the pale mint land 15.0:1, on white 17.7:1), so no
 *   shape relies on mint, peach or gold against the land.
 */

@layer blocks {
  .hm {
    --land: var(--color-mint-pale);
    display: grid;
    gap: var(--space-5);
    max-width: 60rem;
    margin: 0 auto;
  }

  .hm__side,
  .hm__map {
    min-width: 0;
    margin: 0;
  }

  [data-tier="single"] {
    --tier: var(--color-brand);
  }

  [data-tier="regional"] {
    --tier: var(--color-accent-2);
  }

  /* Network: butter fills the selected tab, soft gold the map points,
     swatch and arcs (no dark gold, owner decision 2026-10-25) */
  [data-tier="network"] {
    --tier: var(--color-butter);
    --tier-mark: var(--color-gold-soft);
  }

  /* Tabs: real tab buttons in a segmented row (pill, tier swatch, own selected
     state), not .btn variants; their type, padding and gap follow the shared
     button's tokens (design system "Buttons", 2026-10-24) */
  .hm__tabs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-1);
    margin-block-end: var(--space-3);
  }

  .hm__tabs[hidden] {
    display: none;
  }

  .hm__tab {
    display: flex;
    align-items: center;
    gap: var(--btn-gap);
    padding: var(--btn-padding);
    border: 1px solid var(--color-ink);
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--color-ink);
    font: var(--btn-weight) var(--btn-font-size) / 1.2 var(--font-body);
    letter-spacing: var(--btn-tracking);
    text-transform: uppercase;
    cursor: pointer;
  }

  .hm__tab:hover {
    background: color-mix(in srgb, var(--tier) 40%, transparent);
  }

  .hm__tab[aria-selected="true"] {
    background: var(--tier);
    font-weight: var(--weight-strong);
    box-shadow: 3px 3px 0 var(--color-ink);
  }

  .hm__tab:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 3px;
  }

  .hm__swatch {
    flex: none;
    width: 0.75rem;
    height: 0.75rem;
    border: 1.5px solid var(--color-ink);
    border-radius: 50%;
    background: var(--tier-mark, var(--tier));
  }

  /* The map's box is reserved before the SVG paints: no layout shift */
  .hm__frame {
    aspect-ratio: 8 / 5;
  }

  .hm__svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
  }

  .hm-land {
    fill: var(--land);
  }

  .hm-states {
    fill: none;
    stroke: var(--color-white);
    stroke-width: 1;
    stroke-linejoin: round;
  }

  .hm-arc {
    fill: none;
    stroke: var(--tier-mark, var(--tier));
    stroke-width: 2;
    stroke-linecap: round;
  }

  .hm-arc--case {
    stroke: var(--color-ink);
    stroke-width: 4.5;
  }

  .hm-hub,
  .hm-city {
    fill: var(--tier-mark, var(--tier));
    stroke: var(--color-ink);
    stroke-width: 1.75;
  }

  .hm-pulse {
    fill: none;
    stroke: var(--color-ink);
    stroke-width: 1.5;
    opacity: 0;
  }

  .hm-lens__disc {
    fill: var(--land);
    stroke: var(--color-ink);
    stroke-width: 1.5;
  }

  .hm-lens__src,
  .hm-lens__leader {
    fill: none;
    stroke: var(--color-ink);
    stroke-width: 1.25;
  }

  .hm-label {
    fill: var(--color-ink);
    font-family: var(--font-body);
    font-size: 15px;
    font-weight: 600;
    paint-order: stroke;
    stroke: var(--land);
    stroke-width: 4px;
    stroke-linejoin: round;
  }

  /* Below 48rem the map is under 720px wide and its labels would be under
     11px: hidden there; the description under the map names every city */
  @media (max-width: 47.99rem) {
    .hm-label {
      display: none;
    }
  }

  /* With JS: one tier on the map, one panel under it (the others are kept in
     the same grid cell, so switching never changes the height) */
  .hm.is-tabbed .hm-tier:not(.is-active) {
    opacity: 0;
  }

  .hm__panels {
    display: grid;
    gap: var(--space-3);
    max-width: var(--measure);
    margin: var(--space-3) auto 0;
  }

  .hm.is-tabbed .hm__panel {
    grid-area: 1 / 1;
  }

  .hm.is-tabbed .hm__panel:not(.is-active) {
    visibility: hidden;
  }

  .hm__name {
    font-weight: var(--weight-strong);
  }

  .hm__name .hm__swatch {
    display: inline-block;
    margin-inline-end: 0.4em;
    vertical-align: -0.05em;
  }

  .hm__alt {
    margin: 0;
  }

  .hm__links {
    display: flex;
    flex-wrap: wrap;
    gap: 0 var(--space-3);
    margin: var(--space-3) 0 0;
  }

  .hm__caption {
    margin-block-start: var(--space-3);
    color: var(--color-muted);
    font-size: var(--step--1);
    text-align: center;
  }

  /* From 1024px: the text on the left, the map on the right, centered on each other */
  @media (min-width: 64rem) {
    .hm {
      grid-template-columns: minmax(0, 45fr) minmax(0, 55fr);
      gap: var(--space-5) var(--space-6);
      align-items: center;
      max-width: none;
    }

    .hm .section__head {
      max-width: none;
      margin-inline: 0;
      text-align: left;
    }

    .hm .section__head .section__title,
    .hm .section__head .section__intro {
      margin-inline: 0;
      text-align: left;
    }

    .hm__tabs {
      justify-content: flex-start;
    }

    .hm__panels {
      margin-inline: 0;
    }

    .hm__buttons {
      justify-content: flex-start;
    }
  }
}

@layer motion {
  @media screen and (prefers-reduced-motion: no-preference) {
    /* fx:map ---- US map: on scroll-in (motion.js adds is-in to [data-play]) and on each tab
       switch, the tier cross-fades in, its lens grows, arcs draw from the hub (stroke-dashoffset
       on pathLength 1), city dots and the hub pop, labels fade in; then the hub pulses. Only
       transform, opacity and stroke-dashoffset move. The keyframes name only their start
       state, so without the key the map is complete. */
    html[data-fx~="map"] .hm.is-tabbed .hm-tier {
      transition: opacity 240ms var(--ease-out);
    }

    html[data-fx~="map"] .hm :is(.hm-hub, .hm-city, .hm-pulse, .hm-lens__disc) {
      transform-box: fill-box;
      transform-origin: center;
    }

    html.js-motion[data-fx~="map"] .hm.is-tabbed:not(.is-in) .hm-tier.is-active :is(.hm-arc, .hm-lens__leader) {
      stroke-dasharray: 1;
      stroke-dashoffset: 1;
    }

    html.js-motion[data-fx~="map"] .hm.is-tabbed:not(.is-in) .hm-tier.is-active :is(.hm-hub, .hm-city, .hm-label, .hm-lens) {
      opacity: 0;
    }

    html[data-fx~="map"] .hm.is-tabbed.is-in .is-active .hm-lens {
      animation: hm-fade 360ms var(--ease-out) both;
    }

    html[data-fx~="map"] .hm.is-tabbed.is-in .is-active .hm-lens__disc {
      animation: hm-grow 520ms var(--ease-out) both;
    }

    html[data-fx~="map"] .hm.is-tabbed.is-in .is-active :is(.hm-arc, .hm-lens__leader) {
      stroke-dasharray: 1;
      animation: hm-draw 800ms var(--ease-out) both;
      animation-delay: calc(var(--i, 0) * 70ms + 260ms);
    }

    html[data-fx~="map"] .hm.is-tabbed.is-in .is-active .hm-hub {
      animation: hm-pop 420ms var(--ease-pop) both;
      animation-delay: 120ms;
    }

    html[data-fx~="map"] .hm.is-tabbed.is-in .is-active .hm-city {
      animation: hm-pop 420ms var(--ease-pop) both;
      animation-delay: calc(var(--i, 0) * 70ms + 820ms);
    }

    html[data-fx~="map"] .hm.is-tabbed.is-in .is-active .hm-label {
      animation: hm-fade 400ms var(--ease-out) 1000ms both;
    }

    html[data-fx~="map"] .hm.is-tabbed.is-in .is-active .hm-pulse {
      animation: hm-pulse 2.6s var(--ease-out) 1.4s infinite;
    }
    /* /fx:map */
  }

  @keyframes hm-draw {
    from {
      stroke-dashoffset: 1;
    }
  }

  @keyframes hm-pop {
    from {
      opacity: 0;
      transform: scale(0);
    }
  }

  @keyframes hm-grow {
    from {
      transform: scale(0.2);
    }
  }

  @keyframes hm-fade {
    from {
      opacity: 0;
    }
  }

  @keyframes hm-pulse {
    from {
      opacity: 0.7;
      transform: scale(1);
    }

    to {
      opacity: 0;
      transform: scale(2.8);
    }
  }
}

/* On an ink section (the home map, review 2026-10-26): the tabs, the caption
   and the button read on ink, as the map did inside the home's ink band */
@layer blocks {
  .section--ink .hm__tab {
    border-color: currentcolor;
    color: inherit;
  }

  .section--ink .hm__tab[aria-selected="true"] {
    color: var(--color-ink);
    box-shadow: 3px 3px 0 var(--color-white);
  }

  .section--ink .hm__caption {
    color: var(--color-brand);
  }

  .hm__buttons {
    margin-block-start: var(--space-4);
  }
}
