/* ============================================================
   Section 5 · Location — "Minutes From Everything That Matters."
   Not grouped cards, not a carousel: a sticky cartographic map
   instrument paired with an editorial route ledger — five
   categories strung along a single ember spine, each a compact
   directory of places (name + dotted leader + distance), read
   like a curated address dossier. To keep the section short, each
   category collapses to a single header row; only one opens at a
   time, expanding via a smooth CSS-grid height animation (no
   abrupt max-height guesswork, no snapping) paired with a
   delayed content fade for a layered, unhurried reveal.
   ============================================================ */

.s5 {
  position: relative;
  overflow: hidden;
  background: var(--ground);
  padding: clamp(2rem, 5vh, 4.5rem) 0;
  isolation: isolate;
}

/* ambient depth — mirrors s2/s4's corner-arc device, anchored bottom-left
   this time, in ember rather than terracotta */
.s5::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(
      circle at 6% 96%,
      transparent 13.6rem,
      color-mix(in srgb, var(--ember) 16%, transparent) 13.9rem,
      transparent 14.3rem,
      transparent 19.1rem,
      color-mix(in srgb, var(--ember) 9%, transparent) 19.4rem,
      transparent 19.8rem
    ),
    linear-gradient(
      to bottom,
      var(--ground-deep) 0%,
      var(--ground) 18%,
      var(--ground) 82%,
      var(--ground-deep) 100%
    );
}

.s5-wrap {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--page-x);
}

/* ---------- editorial intro ---------- */

.s5-heading {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(1.9rem, 3.4vw, 3.1rem);
  line-height: 1.12;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-top: 0.6rem;
}

.s5-heading em {
  display: block;
  margin-top: 0.1em;
  font-style: italic;
  color: var(--ember);
}

.s5-sub {
  margin-top: 1rem;
  font-size: clamp(1rem, 0.8vw + 0.7rem, 1.14rem);
  line-height: 1.55;
  color: var(--ink-soft);
}

/* ---------- stage: sticky map + route ledger ---------- */
.s5-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  column-gap: clamp(1.75rem, 4vw, 4rem);
  align-items: start;
  margin-top: clamp(2.75rem, 6vw, 4.5rem);
}

/* ---------- map instrument ---------- */
.s5-map {
  position: sticky;
  top: calc(var(--header-h) + 2rem);
}

.s5-map-frame {
  position: relative;
  overflow: hidden;
  height: clamp(24rem, 54vh, 34rem);
  border-radius: 4px;
  background: var(--ground-deep);
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.55);
}

.s5-map-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  filter: grayscale(28%) invert(90%) hue-rotate(180deg) brightness(0.94)
    contrast(0.92) saturate(1.15);
}

.s5-map-tint {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: color-mix(in srgb, var(--midnight) 40%, transparent);
  mix-blend-mode: multiply;
}

.s5-map-tick {
  position: absolute;
  z-index: 2;
  width: 1.5rem;
  height: 1.5rem;
  pointer-events: none;
  transition:
    border-color 0.4s ease,
    width 0.4s ease,
    height 0.4s ease;
}

.s5-map-tick-tl {
  top: 1rem;
  left: 1rem;
  border-top: 1px solid var(--hairline-ember);
  border-left: 1px solid var(--hairline-ember);
}

.s5-map-tick-br {
  bottom: 1rem;
  right: 1rem;
  border-bottom: 1px solid var(--hairline-ember);
  border-right: 1px solid var(--hairline-ember);
}

.s5-map-frame:hover .s5-map-tick {
  border-color: var(--ember);
  width: 1.9rem;
  height: 1.9rem;
}

.s5-map-caption {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: clamp(1.1rem, 2.4vw, 1.6rem);
  background: linear-gradient(
    to top,
    var(--midnight) 0%,
    color-mix(in srgb, var(--midnight) 55%, transparent) 60%,
    transparent 100%
  );
}

.s5-map-pin {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  color: var(--ember);
}

.s5-map-name {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(0.95rem, 1.4vw, 1.15rem);
  color: var(--ink);
}

.s5-map-name i {
  display: block;
  margin-top: 0.15em;
  font-style: normal;
  font-family: var(--font-body);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.s5-map-link {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ember);
  white-space: nowrap;
  transition: gap 0.3s ease;
}

.s5-map-link svg {
  width: 0.85rem;
  height: 0.85rem;
  transition: transform 0.3s ease;
}

.s5-map-link:hover {
  gap: 0.6rem;
}

.s5-map-link:hover svg {
  transform: translate(2px, -2px);
}

.s5-map-coord {
  margin-top: 0.9rem;
  font-family: var(--font-body);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
}

/* ---------- route ledger ---------- */
.s5-index {
  display: flex;
  flex-direction: column;
}

.s5-cat {
  position: relative;
  padding: clamp(1rem, 1vw, 1rem) 0 clamp(1rem, 1.2vw, 0.9rem) 1rem;
  border-top: 1px solid var(--hairline);
}

.s5-cat:first-child {
  border-top: none;
  padding-top: 10px;
}

/* the connecting spine, one continuous ember line down the column —
   centred under the numbered node, both anchored inside the category's
   own gutter (never a negative offset into the page margin, so neither
   can overflow the viewport at narrow widths) */
.s5-cat::before {
  content: "";
  position: absolute;
  left: 0.56rem;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--hairline-ember);
}

.s5-cat:first-child::before {
  top: 0.9rem;
}

.s5-cat:last-child::before {
  bottom: calc(100% - 0.9rem);
}

/* the whole header row is the expand/collapse trigger */
.s5-cat-toggle {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
  text-align: left;
}

.s5-cat-head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
}

/* the numbered node sitting on the spine */
.s5-cat-num {
  position: absolute;
  left: 0;
  top: 0.15rem;
  width: 1.15rem;
  height: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.62rem;
  color: var(--ground);
  background: var(--ember);
  border-radius: 50%;
  transition: box-shadow 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.s5-cat.is-open .s5-cat-num {
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--ember) 20%, transparent);
}

.s5-cat-name {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(1.2rem, 1.7vw, 1.55rem);
  letter-spacing: -0.01em;
  color: var(--ink);
  transition: color 0.4s ease;
}

.s5-cat-toggle:hover .s5-cat-name,
.s5-cat-toggle:focus-visible .s5-cat-name,
.s5-cat.is-open .s5-cat-name {
  color: var(--ember);
}

.s5-cat-tag {
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--ink-faint);
}

/* the expand indicator — a plus that folds into a cross, echoing
   the residence gallery's res-plus device elsewhere on the page */
.s5-cat-plus {
  position: relative;
  flex: none;
  width: 0.8rem;
  height: 0.8rem;
  transition: transform 0.55s cubic-bezier(0.34, 1.4, 0.4, 1);
}

.s5-cat-plus::before,
.s5-cat-plus::after {
  content: "";
  position: absolute;
  background: var(--ember);
  transition: opacity 0.3s ease;
}

.s5-cat-plus::before {
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
  transform: translateY(-50%);
}

.s5-cat-plus::after {
  left: 50%;
  top: 0;
  height: 100%;
  width: 1px;
  transform: translateX(-50%);
}

.s5-cat.is-open .s5-cat-plus {
  transform: rotate(135deg);
}

/* ---------- the collapsing panel ---------- */
/* a 0fr/1fr grid track animates smoothly to the content's real
   height with no fixed max-height guess and no jump at the end */
.s5-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.65s cubic-bezier(0.16, 1, 0.3, 1);
}

.s5-cat.is-open .s5-panel {
  grid-template-rows: 1fr;
}

.s5-rows {
  list-style: none;
  padding-top: 1.1rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  opacity: 0;
  transform: translateY(-8px);
  transition:
    opacity 0.45s ease,
    transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.s5-cat.is-open .s5-rows {
  opacity: 1;
  transform: none;
  transition-delay: 0.2s;
}

.s5-row {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  padding: 0.6rem 0.4rem;
  margin: 0 -0.4rem;
  border-radius: 2px;
  transition:
    background-color 0.35s ease,
    transform 0.35s ease;
}

.s5-row-name {
  flex: 0 1 auto;
  min-width: 0;
  font-family: var(--font-body);
  font-size: 0.92rem;
  color: var(--ink-soft);
  transition: color 0.35s ease;
}

.s5-row-lead {
  flex: 1;
  min-width: 1.5rem;
  border-bottom: 1px dotted var(--hairline);
  transform: translateY(-0.3em);
}

.s5-row-dist {
  flex: none;
  font-family: var(--font-body);
  font-size: 0.76rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  white-space: nowrap;
  transition: color 0.35s ease;
}

.s5-row.is-upcoming .s5-row-dist {
  font-style: italic;
  color: var(--ember);
}

.s5-row:hover {
  background: var(--ground-raised);
  transform: translateX(0.3rem);
}

.s5-row:hover .s5-row-name {
  color: var(--ink);
}

.s5-row:hover .s5-row-dist {
  color: var(--ember);
}

/* ---------- scroll reveal ---------- */
.s5-intro > *,
.s5-map,
.s5-cat {
  opacity: 0;
  transform: translateY(28px);
  transition:
    opacity 0.9s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.9s cubic-bezier(0.16, 1, 0.3, 1);
}

.s5.is-in .s5-intro > *,
.s5.is-in .s5-map,
.s5.is-in .s5-cat {
  opacity: 1;
  transform: none;
}

.s5.is-in .s5-heading {
  transition-delay: 0.05s;
}
.s5.is-in .s5-sub {
  transition-delay: 0.1s;
}
.s5.is-in .s5-map {
  transition-delay: 0.16s;
}
.s5.is-in .s5-cat:nth-child(1) {
  transition-delay: 0.2s;
}
.s5.is-in .s5-cat:nth-child(2) {
  transition-delay: 0.26s;
}
.s5.is-in .s5-cat:nth-child(3) {
  transition-delay: 0.32s;
}
.s5.is-in .s5-cat:nth-child(4) {
  transition-delay: 0.38s;
}
.s5.is-in .s5-cat:nth-child(5) {
  transition-delay: 0.44s;
}

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .s5-stage {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .s5-map {
    position: static;
  }

  .s5-map-frame {
    height: clamp(18rem, 68vw, 24rem);
  }
}

@media (max-width: 560px) {
  .s5-heading {
    font-size: clamp(1.6rem, 7vw, 2.1rem);
  }

  .s5-cat {
    padding-left: 1.85rem;
  }

  .s5-cat-num {
    width: 0.95rem;
    height: 0.95rem;
    font-size: 0.56rem;
  }

  .s5-cat::before {
    left: 0.46rem;
  }

  .s5-row {
    flex-wrap: wrap;
  }

  .s5-row-lead {
    order: 3;
    flex-basis: 100%;
    display: none;
  }

  .s5-row-name {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .s5-intro > *,
  .s5-map,
  .s5-cat,
  .s5-row,
  .s5-panel,
  .s5-rows,
  .s5-cat-plus,
  .s5-cat-num {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
}
