/* My story: opening, journey map, chapter timeline, flip cards, closing. */

.story-open {
  padding-block: var(--section) 32px;
  max-width: 900px;
}

.story-open__title {
  margin: 8px 0 16px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: var(--fs-h1);
  line-height: 0.98;
  text-wrap: balance;
}

.story-map-wrap {
  padding-block: 8px;
}

.story-map {
  display: block;
  width: 100%;
  height: auto;
}

.story-map__bg {
  fill: var(--tint);
}

.story-map__route {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: calc(1 - var(--progress, 1));
}

.story-map__dot {
  fill: var(--accent);
}

/* While the route follows the reader (JS on, motion allowed), stops not yet
   reached are faded. Without JS every stop shows at full strength. */
.story-map__stop {
  transition: opacity 0.3s ease;
}

.story-map.is-live .story-map__stop:not(.is-reached) {
  opacity: 0.3;
}

.story-map__dot--home {
  fill: var(--accent);
  stroke: var(--paper);
  stroke-width: 3;
}

.story-map__label {
  fill: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 700;
}

.story-map__year {
  fill: var(--soft);
  font-family: var(--sans);
  font-size: 11px;
}

/* A thin halo in the map colour keeps names readable where they meet a line. */
.story-map__label,
.story-map__year {
  paint-order: stroke;
  stroke: var(--tint);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.story-chapters {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding-block: var(--section);
}

.story-chapter {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding-block: 32px;
  border-top: 1px solid var(--line);
}

.story-chapter:first-child {
  border-top: 0;
}

.story-chapter__year {
  font-family: var(--serif);
  font-size: 48px;
  line-height: 1;
  color: var(--accent);
}

.story-chapter__place {
  margin: 0;
  color: var(--soft);
}

.story-chapter__title {
  margin: 4px 0 12px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: var(--fs-h2);
  line-height: 1.05;
}

.story-chapter__body p {
  max-width: 68ch;
  margin: 0 0 16px;
}

.story-chapter__figure {
  margin: 24px 0 8px;
}

.story-chapter__img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: var(--radius);
}

.story-audio {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.story-audio[aria-pressed="true"] {
  background: var(--accent);
  color: var(--paper);
}

.story-audio .icon {
  width: 20px;
  height: 20px;
}

.story-audio__transcript {
  margin-top: 12px;
  max-width: 60ch;
  font-size: var(--fs-small);
  color: var(--muted);
}

.story-audio__transcript summary {
  display: inline-block;
  min-height: 24px;
  color: var(--accent);
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

.story-audio__transcript p {
  margin-top: 8px;
  font-style: italic;
}

.story-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 24px;
}

.flip-card {
  position: relative;
  height: 170px;
  padding: 0;
  border: 0;
  background: none;
  perspective: 800px;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.flip-card__inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}

.flip-card[aria-pressed="true"] .flip-card__inner {
  transform: rotateY(180deg);
}

.flip-card__face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  border-radius: var(--radius-lg);
  backface-visibility: hidden;
  background: var(--tint);
}

.flip-card__back {
  transform: rotateY(180deg);
  background: var(--paper);
  border: 1px solid var(--line);
}

.flip-card__back p {
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
}

.flip-card__title {
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.15;
  color: var(--ink);
}

.flip-card__hint {
  font-size: 12px;
  color: var(--soft);
}

.story-close__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.story-close__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 8px;
}

@media (min-width: 720px) {
  .story-cards {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  /* Desktop: chapters on the left, the map beside them on the right. The map
     sticks while the chapters scroll, so the route can be seen drawing
     without covering the text. */
  .story-journey {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 520px);
    column-gap: 56px;
    align-items: start;
  }

  .story-map-wrap {
    grid-column: 2;
    grid-row: 1;
    position: sticky;
    top: calc(var(--header-h) + 24px);
    padding-block: var(--section) 0;
  }

  .story-chapters {
    grid-column: 1;
    grid-row: 1;
  }

  .story-chapter {
    grid-template-columns: 120px minmax(0, 1fr);
    gap: 32px;
    padding-block: 48px;
  }

  /* A chapter without a year keeps its text in the content column. */
  .story-chapter__body {
    grid-column: 2;
  }

  /* The map is drawn smaller beside the chapters: larger text keeps the
     labels readable. */
  .story-map__label {
    font-size: 16px;
  }

  .story-map__year {
    font-size: 13px;
  }

  .story-journey .story-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .story-chapter__year {
    position: sticky;
    top: calc(var(--header-h) + 24px);
    align-self: start;
    font-size: 64px;
  }

  .flip-card {
    height: 200px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flip-card__inner {
    transition: none;
    transform: none;
  }

  .flip-card__face {
    position: relative;
    backface-visibility: visible;
  }

  .flip-card__back {
    display: none;
    transform: none;
  }

  .flip-card[aria-pressed="true"] .flip-card__front {
    display: none;
  }

  .flip-card[aria-pressed="true"] .flip-card__back {
    display: flex;
  }
}
