:root {
  color-scheme: dark;
  --void: #02010a;
  --midnight: #04052e;
  --plum: #140152;
  --violet: #22007c;
  --blue: #0d00a4;
  --paper: #f5f2ff;
  --paper-soft: #e8e4ff;
  --ink: #070418;
  --muted: #625a82;
  --indigo: var(--violet);
  --celadon: #9a94ff;
  --vermilion: var(--blue);
  --gold: #d7d2ff;
  --line: rgba(34, 0, 124, 0.28);
  --font-body: "Shippori Mincho", Georgia, serif;
  --font-ui: "Atkinson Hyperlegible", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 12% 8%, rgba(13, 0, 164, 0.44), transparent 24rem),
    radial-gradient(circle at 88% 24%, rgba(34, 0, 124, 0.34), transparent 28rem),
    linear-gradient(180deg, var(--midnight), var(--plum) 48%, var(--void));
  color: var(--paper);
  font-family: var(--font-body);
}

button {
  font: inherit;
}

img {
  display: block;
  max-width: 100%;
}

.skip-link {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 50;
  transform: translateY(-200%);
  background: var(--paper);
  color: var(--paper);
  color: var(--void);
  padding: 0.75rem 1rem;
  font-family: var(--font-ui);
}

.skip-link:focus {
  transform: translateY(0);
}

.map-story {
  position: relative;
  min-height: 100svh;
}

.map-stage {
  position: sticky;
  top: 0;
  z-index: 0;
  height: 100svh;
  overflow: hidden;
  background:
    radial-gradient(circle at 52% 34%, rgba(13, 0, 164, 0.42), transparent 24rem),
    radial-gradient(circle at 72% 62%, rgba(34, 0, 124, 0.48), transparent 30rem),
    linear-gradient(135deg, var(--void), var(--midnight) 42%, var(--plum) 72%, var(--violet));
  isolation: isolate;
}

#japan-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 700ms cubic-bezier(0.16, 1, 0.3, 1);
}

.map-stage--ready #japan-map {
  opacity: 1;
}

.map-shade {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(2, 1, 10, 0.72), transparent 48%, rgba(20, 1, 82, 0.18)),
    linear-gradient(0deg, rgba(2, 1, 10, 0.62), transparent 34%, rgba(4, 5, 46, 0.26));
}

.map-title {
  position: absolute;
  left: clamp(1.5rem, 5vw, 5rem);
  bottom: clamp(4.5rem, 13vh, 9rem);
  z-index: 2;
  width: min(820px, calc(100vw - 3rem));
  color: var(--paper);
  opacity: 0;
  transform: translateY(1.5rem);
  transition: opacity 500ms ease, transform 700ms cubic-bezier(0.16, 1, 0.3, 1);
}

.map-title.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.map-title h1 {
  margin: 0;
  max-width: 13ch;
  font-size: clamp(2.8rem, 6.2vw, 6.6rem);
  line-height: 0.96;
  letter-spacing: 0;
  text-wrap: balance;
}

.map-pin-labels {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.map-pin-label {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 11rem;
  padding: 0.38rem 0.55rem;
  border: 1px solid rgba(215, 210, 255, 0.72);
  border-radius: 999px;
  background: rgba(4, 5, 46, 0.82);
  color: var(--paper);
  box-shadow: 0 0.45rem 1.1rem rgba(2, 1, 10, 0.42);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.1;
  opacity: 0;
  pointer-events: auto;
  white-space: nowrap;
  transition:
    opacity 180ms ease,
    background 180ms ease,
    border-color 180ms ease,
    color 180ms ease;
}

.map-pin-label.is-visible {
  opacity: 0.72;
}

.map-pin-label.is-active,
.map-pin-label:hover,
.map-pin-label:focus-visible {
  border-color: var(--gold);
  background: rgba(20, 1, 82, 0.92);
  color: var(--gold);
  opacity: 1;
}

body[data-active-stop="overview"] .map-pin-label {
  opacity: 0;
  pointer-events: none;
}

body[data-pin-calibration="true"][data-active-stop="overview"] .map-pin-label.is-visible {
  opacity: 0.72;
  pointer-events: auto;
}

.pin-calibrator {
  position: fixed;
  left: 1rem;
  top: 1rem;
  z-index: 60;
  width: min(24rem, calc(100vw - 2rem));
  max-height: calc(100svh - 2rem);
  overflow: auto;
  border: 1px solid rgba(215, 210, 255, 0.5);
  background: rgba(4, 5, 46, 0.94);
  color: var(--paper);
  box-shadow: 0 1.1rem 3rem rgba(2, 1, 10, 0.5);
  font-family: var(--font-ui);
}

.pin-calibrator details {
  padding: 0.85rem;
}

.pin-calibrator summary {
  cursor: pointer;
  color: var(--gold);
  font-weight: 700;
}

.pin-calibrator__note {
  margin: 0.5rem 0 0;
  color: rgba(245, 242, 255, 0.74);
  font-size: 0.72rem;
  line-height: 1.45;
}

.pin-calibrator__advanced {
  margin-top: 0.8rem;
  border-top: 1px solid rgba(215, 210, 255, 0.24);
  padding-top: 0.7rem;
}

.pin-calibrator__advanced summary {
  color: var(--paper);
  font-size: 0.78rem;
}

.pin-calibrator__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: 0.85rem;
}

.pin-calibrator label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.72rem;
  font-weight: 700;
}

.pin-calibrator input[type="number"] {
  width: 100%;
  border: 1px solid rgba(34, 0, 124, 0.42);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  padding: 0.4rem;
}

.pin-calibrator__toggle {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.pin-calibrator__nudges,
.pin-calibrator__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.pin-calibrator button {
  border: 1px solid rgba(215, 210, 255, 0.42);
  border-radius: 0;
  background: var(--plum);
  color: var(--paper);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.45rem 0.58rem;
}

.pin-calibrator button:hover,
.pin-calibrator button:focus-visible {
  border-color: var(--gold);
  color: var(--gold);
}

.pin-calibrator textarea {
  display: block;
  width: 100%;
  min-height: 11rem;
  margin-top: 0.8rem;
  border: 1px solid rgba(215, 210, 255, 0.42);
  border-radius: 0;
  background: var(--void);
  color: var(--paper);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.68rem;
  line-height: 1.45;
  padding: 0.55rem;
  resize: vertical;
}

.axis-gizmo {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 60;
  width: 124px;
  height: 124px;
  border: 1px solid rgba(215, 210, 255, 0.38);
  background: rgba(2, 1, 10, 0.52);
  box-shadow: 0 0.8rem 2rem rgba(2, 1, 10, 0.42);
  pointer-events: none;
}

.map-status,
.map-fallback {
  position: absolute;
  z-index: 4;
  left: clamp(1rem, 3vw, 3rem);
  top: clamp(1rem, 3vw, 3rem);
  max-width: min(420px, calc(100vw - 2rem));
  font-family: var(--font-ui);
}

.map-status {
  color: var(--paper);
  font-size: 0.88rem;
}

.map-fallback {
  display: none;
  gap: 0.35rem;
  padding: 1rem;
  border: 1px solid rgba(215, 210, 255, 0.42);
  background:
    linear-gradient(90deg, rgba(2, 1, 10, 0.88), rgba(20, 1, 82, 0.72)),
    url("../3djapan/background.jpeg") center / cover;
  color: var(--paper);
}

.map-stage--failed .map-fallback {
  display: grid;
}

.stop-rail {
  position: absolute;
  right: clamp(0.8rem, 2.5vw, 2rem);
  top: 50%;
  z-index: 5;
  display: grid;
  gap: 0.65rem;
  transform: translateY(-50%);
}

.stop-dot {
  position: relative;
  width: 0.82rem;
  height: 0.82rem;
  border: 1px solid rgba(215, 210, 255, 0.72);
  border-radius: 999px;
  background: rgba(245, 242, 255, 0.16);
  cursor: pointer;
}

.stop-dot span {
  position: absolute;
  right: 1.25rem;
  top: 50%;
  min-width: max-content;
  transform: translateY(-50%);
  color: var(--paper);
  font-family: var(--font-ui);
  font-size: 0.76rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.stop-dot:hover span,
.stop-dot.is-active span {
  opacity: 1;
}

.stop-dot.is-active {
  background: var(--gold);
  border-color: var(--gold);
}

.story-panels {
  position: relative;
  z-index: 2;
  margin-top: -100svh;
  padding: 112svh clamp(0.85rem, 3.5vw, 3.75rem) 16svh;
  pointer-events: none;
}

.story-panel {
  min-height: 112svh;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.story-panel--opening {
  min-height: 92svh;
  justify-content: flex-start;
}

.story-card {
  width: min(500px, 100%);
  padding: clamp(0.82rem, 1.7vw, 1.18rem);
  border: 1px solid rgba(34, 0, 124, 0.42);
  background: rgba(245, 242, 255, 0.94);
  color: var(--ink);
  box-shadow: 0 0.9rem 2.6rem rgba(2, 1, 10, 0.42);
  pointer-events: auto;
}

.story-panel:nth-child(even) {
  justify-content: flex-start;
}

.story-card__media {
  overflow: hidden;
  margin-bottom: clamp(0.7rem, 1.4vw, 1rem);
  border: 1px solid var(--line);
  aspect-ratio: 21 / 9;
  background: var(--paper-soft);
}

.story-card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.story-inline-media {
  position: relative;
  overflow: hidden;
  margin: 0.65rem 0 0.9rem;
  border: 1px solid var(--line);
  background: var(--paper-soft);
  aspect-ratio: 16 / 9;
}

.story-inline-media--portrait,
.story-inline-media--book {
  aspect-ratio: 4 / 3;
}

.story-inline-media--wide {
  aspect-ratio: 20 / 9;
}

.story-inline-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.story-inline-media--book img,
.story-inline-media--portrait img {
  object-fit: contain;
}

.story-inline-media figcaption {
  position: absolute;
  inset: auto 0 0;
  padding: 0.48rem 0.58rem;
  background: linear-gradient(180deg, rgba(2, 1, 10, 0), rgba(2, 1, 10, 0.88) 28%, rgba(2, 1, 10, 0.94));
  color: var(--paper);
  font-family: var(--font-ui);
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1.25;
}

.story-inline-media figcaption cite {
  font-style: italic;
}

.story-card__eyebrow {
  margin: 0 0 0.35rem;
  color: var(--blue);
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel-intro,
.panel-prose p,
.panel-prose h3 {
  max-width: 58ch;
}

.panel-intro,
.panel-prose p {
  margin: 0 0 0.9rem;
  font-size: clamp(0.92rem, 0.95vw, 1rem);
  line-height: 1.62;
}

.panel-prose h3 {
  margin: 1.35rem 0 0.55rem;
  color: var(--indigo);
  font-size: clamp(1.12rem, 1.55vw, 1.62rem);
  line-height: 1.14;
  letter-spacing: 0;
}

.panel-prose h3:first-child {
  margin-top: 0;
}

.image-river {
  position: relative;
  z-index: 3;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(260px, 42vw);
  gap: clamp(0.8rem, 2vw, 1.5rem);
  overflow-x: auto;
  padding: clamp(2rem, 6vw, 5rem) clamp(1rem, 4vw, 5rem);
  scroll-snap-type: x mandatory;
  background:
    radial-gradient(circle at 8% 40%, rgba(13, 0, 164, 0.26), transparent 18rem),
    linear-gradient(90deg, var(--void), var(--midnight), var(--plum));
}

.river-panel {
  position: relative;
  margin: 0;
  min-height: 58vh;
  overflow: hidden;
  scroll-snap-align: center;
  border: 1px solid rgba(215, 210, 255, 0.24);
  background: var(--midnight);
}

.river-panel img {
  width: 100%;
  height: 100%;
  min-height: 58vh;
  object-fit: cover;
  filter: saturate(0.94);
}

.bibliography-shell {
  position: relative;
  z-index: 3;
  display: grid;
  justify-items: center;
  padding: clamp(3rem, 8vw, 8rem) clamp(1rem, 4vw, 5rem);
  background:
    radial-gradient(circle at 18% 10%, rgba(13, 0, 164, 0.28), transparent 24rem),
    linear-gradient(180deg, var(--plum), var(--midnight) 58%, var(--void));
  color: var(--paper);
}

.bibliography-shell > div {
  width: min(100%, 78ch);
}

.bibliography-shell h2 {
  margin: 0 0 2rem;
  color: var(--gold);
  font-size: clamp(2rem, 4vw, 4rem);
  line-height: 1;
}

.bibliography-shell p {
  margin: 0 0 1rem;
  color: rgba(245, 242, 255, 0.86);
  font-size: clamp(1rem, 1.2vw, 1.16rem);
  line-height: 1.8;
}

.credits {
  position: relative;
  z-index: 3;
  padding: clamp(2rem, 5vw, 4rem) clamp(1rem, 4vw, 5rem);
  background: var(--void);
  color: rgba(245, 242, 255, 0.84);
  font-family: var(--font-ui);
}

.credits h2 {
  margin: 0 0 1rem;
  font-size: 1rem;
}

.credits p,
.credits li {
  max-width: 82ch;
  color: rgba(245, 242, 255, 0.72);
  font-size: 0.86rem;
  line-height: 1.7;
}

.credits ul {
  padding-left: 1.1rem;
}

@media (max-width: 900px) {
  .map-stage {
    position: relative;
    height: 76svh;
  }

  .map-title {
    bottom: clamp(2rem, 8vh, 4rem);
  }

  .map-title h1 {
    font-size: clamp(2.5rem, 13vw, 4.5rem);
  }

  .stop-rail {
    inset: auto 1rem 1rem 1rem;
    display: flex;
    justify-content: center;
    transform: none;
  }

  .stop-dot span {
    display: none;
  }

  .map-pin-label {
    max-width: 8rem;
    padding: 0.32rem 0.48rem;
    font-size: 0.66rem;
  }

  .story-panels {
    margin-top: 0;
    padding: clamp(1rem, 5vw, 2rem);
  }

  .story-panel,
  .story-panel--opening {
    min-height: auto;
    display: block;
    margin-bottom: 1rem;
  }

  .story-card {
    width: 100%;
  }

  .image-river {
    grid-auto-columns: minmax(260px, 82vw);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
