/**
 * Story map: sticky map, scrolling prose.
 *
 * The layout is a two-column grid on wide screens and a single column on narrow
 * ones. On narrow screens the map becomes a short sticky band at the top rather
 * than disappearing - a phone is where most of this will be read, and a story
 * map with no map on a phone is just a list.
 *
 * Jannah clips .tie-container with overflow:hidden. That box is as tall as the
 * page and never scrolls, so a sticky descendant rides up with the first step
 * instead of staying put for the rest of the route. The override is limited to
 * pages that actually render a story map. The stage is the piece that is tall:
 * on a wide screen it stretches with the steps, and the map sticks inside it.
 * A sticky grid item sized to the map itself has no distance left to stick.
 */

body:has(.mea-story-map-view) .tie-container {
  overflow: visible;
}

.mea-story-map-view {
  margin-block: var(--ai-space-7, 3rem);
}

/* Narrow: no box, so the sticky map's parent is the whole story. */
.mea-story-map-view__stage {
  display: contents;
}

.mea-story-map-view__map {
  background: var(--ai-bg-sunken, #f0f0ee);
  border: 1px solid var(--ai-border, #e2e3eb);
  border-radius: var(--ai-radius, 2px);
}

.mea-story-map-view__steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: mea-story;
}

.mea-story-map-view__step {
  counter-increment: mea-story;
  position: relative;
  padding-inline-start: var(--ai-space-6, 2rem);
  padding-block: var(--ai-space-4, 1rem);
  /* Deliberately generous: each step needs enough height to occupy the
   * viewport band on its own, or two steps fight over the map. */
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  opacity: 0.55;
  transition: opacity var(--ai-transition, 0.25s ease);
}

.mea-story-map-view__step.is-active {
  opacity: 1;
}

/* The number is decoration repeating what the ordered list already conveys,
 * so it is generated content and never reaches the accessibility tree. */
.mea-story-map-view__step::before {
  content: counter(mea-story);
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: var(--ai-space-4, 1rem);
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--ai-font-num, monospace);
  font-size: var(--ai-fs-xs, 0.875rem);
  font-weight: var(--ai-fw-bold, 700);
  color: var(--ai-text-muted, #68697a);
  background: var(--ai-bg-sunken, #f0f0ee);
  border-radius: 50%;
}

.mea-story-map-view__step.is-active::before {
  color: var(--ai-on-brand, #fff);
  background: var(--ai-brand, #005cff);
}

.mea-story-map-view__date {
  margin: 0 0 var(--ai-space-1, 0.25rem);
  font-family: var(--ai-font-num, monospace);
  font-size: var(--ai-fs-2xs, 0.8125rem);
  letter-spacing: 0.04em;
  color: var(--ai-text-muted, #68697a);
}

.mea-story-map-view__title {
  margin: 0 0 var(--ai-space-2, 0.5rem);
  font-size: var(--ai-fs-xl, 1.375rem);
  font-weight: var(--ai-fw-bold, 700);
  line-height: var(--ai-lh-heading, 1.4);
  color: var(--ai-text, #0d0e18);
}

.mea-story-map-view__place {
  margin: 0 0 var(--ai-space-2, 0.5rem);
  font-size: var(--ai-fs-xs, 0.875rem);
  color: var(--ai-gold, #886329);
}

.mea-story-map-view__text {
  font-size: var(--ai-fs-base, 1.0625rem);
  line-height: var(--ai-lh-body, 1.85);
  color: var(--ai-text-body, #484a5e);
}

.mea-story-map-view__text p:last-child {
  margin-block-end: 0;
}

/* -------------------------------------------------------------------
 *  Pins and route
 * ------------------------------------------------------------------- */
.mea-story-pin {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--ai-font-num, monospace);
  font-size: var(--ai-fs-2xs, 0.8125rem);
  font-weight: var(--ai-fw-bold, 700);
  color: var(--ai-text-strong, #2a2c3e);
  background: var(--ai-bg, #fff);
  border: 2px solid var(--ai-hairline, #c0c2d0);
  border-radius: 50%;
  box-shadow: var(--ai-shadow-sm, 0 1px 2px rgba(13, 14, 24, 0.06));
  transition: transform var(--ai-transition, 0.25s ease);
}

.mea-story-pin.is-current {
  color: var(--ai-on-brand, #fff);
  background: var(--ai-brand, #005cff);
  border-color: var(--ai-bg, #fff);
  transform: scale(1.25);
}

.mea-story-path {
  stroke: var(--ai-navy, #040845);
}

/* -------------------------------------------------------------------
 *  Narrow screens: map on top, as a band
 * ------------------------------------------------------------------- */
.mea-story-map-view__map {
  position: sticky;
  inset-block-start: 0;
  z-index: 1;
  height: 42vh;
  margin-block-end: var(--ai-space-4, 1rem);
}

/* -------------------------------------------------------------------
 *  Wide screens: two columns, map beside the prose
 * ------------------------------------------------------------------- */
@media (min-width: 900px) {
  .mea-story-map-view {
    display: grid;
    /* The stage is the tall column. The map sticks inside it, beside the steps. */
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    gap: var(--ai-space-6, 2rem);
    align-items: start;
  }

  .mea-story-map-view__stage {
    display: block;
    grid-column: 2;
    grid-row: 1;
    align-self: stretch;
    min-width: 0;
    position: relative;
  }

  .mea-story-map-view__map {
    /* 6rem rather than 0: the site header is sticky, and a map tucked under it
     * loses its top third exactly where the current pin tends to sit. */
    inset-block-start: 6rem;
    height: min(78vh, 42rem);
    margin-block-end: 0;
  }

  .mea-story-map-view__steps {
    grid-column: 1;
    grid-row: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mea-story-map-view__step,
  .mea-story-pin {
    transition: none;
  }

  /* Without the camera flight there is no reason to dim the inactive steps;
   * full opacity is simply easier to read. */
  .mea-story-map-view__step {
    opacity: 1;
  }
}

@media print {
  .mea-story-map-view {
    display: block;
  }

  .mea-story-map-view__stage,
  .mea-story-map-view__map {
    display: none;
  }

  .mea-story-map-view__step {
    min-height: 0;
    opacity: 1;
    page-break-inside: avoid;
  }
}
