/* 境 Districts. A dark atlas of three cards. Each card swings in from the left in 3D while it is
   uncovered from the top (a clip-path wipe), one after another, and its photo pans inside it.
   (v1 lost the swing: a .reveal rule cancelled it. v2 drops that rule, so it shows.) */

.locations {
  position: relative;
  background: var(--surface-districts);
}
.locations-stage {
  position: relative;
  padding: 118px var(--pad) 70px;
  overflow: clip;
  isolation: isolate;
  background: var(--surface-districts);
}
.locations :is(.locations-head, .district-copy, .district-top, .locations-stage > .chapter-mark) {
  opacity: var(--chapter-ink, 1); /* dims while the ending opens over it */
}
.locations-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  margin: 26px 0 36px;
}
.locations-head > .line {
  max-width: 260px;
  color: #b5baa6;
  text-align: right;
}

/* ---------- Cards ---------- */
.district-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 16px;
  perspective: 1600px;
}
.district-card {
  position: relative;
  display: block;
  width: 100%;
  min-height: 425px;
  padding: 0;
  text-align: left;
  background: #20261b;
  border: 1px solid var(--line);
  overflow: hidden;
  transform-origin: 0 50%;
  transform: translate3d(0, var(--district-y, 0px), var(--district-z, 0px)) rotateY(var(--district-turn, 0deg));
  clip-path: inset(var(--district-cut, 0%) 0 0 0);
  backface-visibility: hidden;
}
.district-card:focus-visible {
  outline-offset: 3px;
}
.district-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.55);
  transform: translateY(var(--district-pan, 0%)) scale(1.14); /* the photo pans inside the card */
  transition:
    filter 0.4s,
    scale 0.6s;
}
/* V3: each card has its own district art now, so the three grades of one city photo (and the red
   multiply layer over the meridian) are gone. */
.district-card:hover img {
  scale: 1.04;
  filter: saturate(0.9);
}
.district-card::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    linear-gradient(180deg, #080e09b0 0, transparent 90px),
    linear-gradient(0deg, #080e09f5 0%, #080e0950 45%, transparent 80%);
}
.district-top {
  position: absolute;
  top: 18px;
  left: 20px;
  right: 20px;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #dcdccb;
}
/* The spirit level: one, two or three vermilion dots before the word */
.danger {
  display: flex;
  align-items: center;
  gap: 8px;
}
.danger::before {
  content: "";
  width: calc(var(--dots) * 10px - 4px);
  height: 6px;
  background: radial-gradient(circle, var(--shu) 2.6px, transparent 3px) 0 0 / 10px 6px repeat-x;
}
.danger[data-level="1"] {
  --dots: 1;
}
.danger[data-level="2"] {
  --dots: 2;
}
.danger[data-level="3"] {
  --dots: 3;
}
.district-copy {
  position: absolute;
  bottom: 22px;
  left: 24px;
  right: 24px;
  z-index: 3;
  display: grid;
  gap: 8px;
  transform: translateY(var(--district-copy-y, 0px));
}
.district-copy > .label {
  color: #e7a596;
}
.district-name {
  max-width: 220px;
  font: 800 var(--text-line) / 1.05 var(--font-display);
  text-transform: uppercase;
}
.district-copy .link {
  justify-self: start;
  margin-top: 6px;
}
.district-card:is(:hover, :focus-visible) .link::after {
  transform: scaleX(1);
}

/* ---------- Tablet ---------- */
@media (max-width: 1100px) {
  .district-grid {
    gap: 12px;
  }
  .district-card {
    min-height: 370px;
  }
}

/* ---------- Tall desktop: the atlas pins and fits one screen ---------- */
@media (min-width: 761px) and (min-height: 780px) {
  .locations-stage {
    position: sticky;
    top: 0;
    min-height: 100svh;
  }
  .district-card {
    min-height: clamp(360px, 47svh, 580px);
  }
}

/* ---------- Phone ---------- */
@media (max-width: 760px) {
  .locations {
    scroll-margin-top: 70px;
  }
  .locations-stage {
    padding: 84px 22px 60px;
  }
  .locations-head {
    display: block;
    margin: 24px 0 30px;
  }
  .locations-head > .line {
    margin-top: 16px;
    text-align: left;
  }
  .district-grid {
    grid-template-columns: 1fr;
    gap: 16px;
    perspective: 1000px;
  }
  .district-card {
    min-height: 370px;
  }
  /* (the phone crops of the shared city photo went with V3's own district art) */
}

/* ---------- Reduced motion ---------- */
html:is(.reduced, .compact-layout) .locations-stage {
  position: relative;
  min-height: 0;
}
html:is(.reduced, .compact-layout) main :is(.district-card, .district-card img, .district-copy) {
  transform: none !important;
  clip-path: none !important;
  opacity: 1 !important;
}
