/* =========================================================
   Atlas — the unified map + chapter viewer.
   Replaces the old .journey + .chapter sections.
   ========================================================= */

/* The atlas tab-view fills its tab area, no scroll.
   Note: display is controlled by .tab-view / .tab-view.is-active rules in index.html;
   we only set styling here so the tab actually hides when another tab is active. */
.tab-view[data-tab="atlas"] {
  position: relative;
  padding: clamp(1rem, 2.5vw, 2rem) clamp(0.75rem, 2.5vw, 2rem);
  background: var(--paper);
  flex-direction: column;
  height: calc(100vh - 60px);
  height: calc(100svh - 60px);
  max-height: calc(100vh - 60px);
  max-height: calc(100svh - 60px);
  overflow: hidden;
}

/* Bridge as a near-invisible background motif */
.atlas-bridge-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.04;
  pointer-events: none;
  z-index: 0;
  filter: saturate(0.6);
}

.atlas-head {
  position: relative;
  z-index: 1;
  max-width: 100%;
  margin: 0 auto clamp(1rem, 2vw, 1.5rem);
  text-align: center;
}

.atlas-head .eyebrow {
  font-family: var(--sans);
  font-size: 0.75rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--vermilion);
  margin-bottom: 0.8rem;
}

.atlas-head h2 {
  font-family: var(--serif-display);
  font-weight: 500;
  font-size: clamp(2rem, 4vw, 3rem);
  letter-spacing: -0.01em;
  margin: 0 0 0.8rem;
  color: var(--ink);
  line-height: 1.15;
}

.atlas-lede {
  margin: 0 auto;
  max-width: 62ch;
  font-family: var(--serif-body);
  font-size: clamp(1.02rem, 1.25vw, 1.15rem);
  color: var(--ink-2);
  line-height: 1.6;
}

/* =========================================================
   The frame: 2-col (map | panel). Aspect roughly 16:9.
   ========================================================= */

.atlas-frame {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  /* Subtle paper card edge */
  background: linear-gradient(180deg, rgba(255,253,247,0.7), rgba(251,247,238,0.3));
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: clamp(1rem, 1.6vw, 1.6rem);
  box-shadow: 0 1px 0 rgba(0,0,0,0.03), 0 20px 40px -30px rgba(60, 40, 20, 0.08);
  min-height: 0;
}

.atlas-body {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(0, 1.1fr);
  gap: clamp(1rem, 2vw, 2rem);
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* =========================================================
   MAP column
   ========================================================= */

.atlas-map {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: 3px;
  background: rgba(244, 240, 230, 0.35);
}

.atlas-map-stage {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
}

.atlas-map[data-active-region="china"]  .atlas-map-stage[data-region="china"],
.atlas-map[data-active-region="taiwan"] .atlas-map-stage[data-region="taiwan"],
.atlas-map[data-active-region="canada"] .atlas-map-stage[data-region="canada"] {
  opacity: 1;
  pointer-events: auto;
}

.atlas-map-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.atlas-map-svg .atlas-land {
  fill: rgba(200, 188, 165, 0.22);
  stroke: rgba(120, 100, 75, 0.4);
  stroke-width: 0.6;
  vector-effect: non-scaling-stroke;
  transition: fill 0.4s ease;
}
.atlas-map-svg .atlas-land.is-highlight {
  fill: rgba(192, 57, 43, 0.16);
  stroke: rgba(192, 57, 43, 0.6);
}

/* Trail SVG — animated line drawn between consecutive chapter pins */
.atlas-map-trail {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}
/* Invisible track — geometric path only, no stroke. The triangle reads the
   getPointAtLength of this path each frame to position itself. */
.atlas-map-trail .trail-path-track {
  fill: none;
  stroke: none;
  pointer-events: none;
}
/* Triangle traveler — the only visible trail element. */
.atlas-map-trail .trail-arrow {
  fill: var(--vermilion, #c0392b);
  stroke: rgba(255, 247, 235, 0.65);
  stroke-width: 0.4;
  vector-effect: non-scaling-stroke;
  opacity: 0;
  filter: drop-shadow(0 0 4px rgba(192, 57, 43, 0.6));
}

/* Pins layer — SVG circles. Sharing the map's viewBox + preserveAspectRatio
   means pins line up exactly with the trail line endpoints and the map paths. */
.atlas-map-pins {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  overflow: visible;
}
.atlas-map-pins .amp-pin {
  cursor: pointer;
  pointer-events: all;
}
.atlas-map-pins .amp-pin .amp-dot {
  /* Diamond marker — soft cream fill with a thin vermilion edge.
     Reads as an elegant location glyph rather than a plain dot. */
  fill: var(--paper, #fbf7ee);
  stroke: var(--vermilion, #c0392b);
  stroke-width: 1.1;
  vector-effect: non-scaling-stroke;
  transition: fill 0.3s ease, stroke-width 0.3s ease;
}
.atlas-map-pins .amp-pin .amp-ring {
  fill: none;
  stroke: var(--vermilion, #c0392b);
  stroke-width: 0.8;
  vector-effect: non-scaling-stroke;
  opacity: 0;
}
.atlas-map-pins .amp-pin.is-active .amp-dot {
  fill: var(--vermilion, #c0392b);
  stroke-width: 1.4;
}
.atlas-map-pins .amp-pin.is-active .amp-ring {
  opacity: 0.75;
  animation: amp-ring 1.8s ease-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}
@keyframes amp-ring {
  0%   { transform: scale(0.45); opacity: 0.75; }
  100% { transform: scale(2.5);  opacity: 0;    }
}

/* Region label, bottom-left of map */
.atlas-map-label {
  position: absolute;
  left: 0.9rem;
  bottom: 0.7rem;
  display: flex;
  flex-direction: column;
  font-family: var(--serif, Georgia, serif);
  pointer-events: none;
  z-index: 3;
}
.atlas-map-region {
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(80, 70, 55, 0.7);
}
.atlas-map-city {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--ink, #2a2620);
  margin-top: 0.1rem;
}

@media (max-width: 760px) {
  .atlas-body {
    grid-template-columns: 1fr;
    /* Map row is generous on bigger phones but the chapter text needs the
       majority of the height. Was 38vh — too tall on 6"–7" devices and
       cut the body text in half. */
    grid-template-rows: minmax(160px, 26vh) minmax(0, 1fr);
  }
}

/* Short / landscape viewports (phone rotated sideways, split-screen,
   short windows). The 2-column desktop layout breaks: the map fills the
   visible area and the chapter panel is unreachable. The prior fix only
   tweaked the grid; the flex chain (.tab-view → .atlas-frame → .atlas-body
   all flex: 1 1 auto with min-height: 0) was still forcing content to
   collapse into the viewport.
   Here we break out of flex entirely: everything becomes block, the map
   is a fixed-size sliver at the top, and the chapter text below scrolls
   naturally with the page. */
@media (max-height: 500px) {
  /* Only the active atlas tab should be visible; the base
     .tab-view { display: none } / .is-active { display: block }
     toggle still applies. Without `.is-active` here we'd unconditionally
     show the atlas tab, pushing Tributes/Photos below the fold. */
  .tab-view.is-active[data-tab="atlas"] {
    display: block;
    height: auto;
    min-height: calc(100vh - 60px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .atlas-frame {
    display: block;
    flex: 0 0 auto;
    min-height: 0;
  }
  .atlas-body {
    display: block;
    flex: 0 0 auto;
    min-height: 0;
    overflow: visible;
  }
  .atlas-map {
    display: block;
    width: 100%;
    height: 180px;
    min-height: 0;
    margin-bottom: 1rem;
  }
  .atlas-panel {
    display: block;
    overflow: visible;
    min-height: 0;
  }
}

/* =========================================================
   CHAPTER PANEL (right column)
   ========================================================= */

.atlas-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

/* ---- Top toolbar: prev | chapter rail | next ---- */
.atlas-toolbar {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  padding: 0 0 0.85rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 1rem;
  flex: 0 0 auto;
}
.atlas-toolbar .atlas-index {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0;
  border-bottom: none;
  margin-bottom: 0;
}
.atlas-prev-top,
.atlas-next-top {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  align-self: stretch;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-2);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
}
.atlas-prev-top:hover:not(:disabled),
.atlas-next-top:hover:not(:disabled) {
  border-color: var(--vermilion);
  color: var(--vermilion);
  background: rgba(192, 57, 43, 0.04);
}
.atlas-prev-top:disabled,
.atlas-next-top:disabled { opacity: 0.3; cursor: default; }

/* ---- Index strip (horizontal pill rail) ---- */
.atlas-index {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 0.35rem;
  padding: 0 0 0.7rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 0.8rem;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}
.atlas-index::-webkit-scrollbar { height: 4px; }
.atlas-index::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 2px; }

.atlas-idx {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  padding: 0.45rem 0.45rem 0.5rem;
  background: transparent;
  border: none;
  border-top: 2px solid transparent;
  border-radius: 0;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: var(--muted);
  transition: color 0.25s ease, border-color 0.25s ease, background 0.25s ease;
  overflow: hidden;
}
.atlas-idx:hover {
  color: var(--ink-2);
  background: rgba(220, 210, 190, 0.15);
}
.atlas-idx.is-active {
  color: var(--ink);
  border-top-color: var(--vermilion);
  background: rgba(192, 57, 43, 0.04);
}
.atlas-idx.is-past { color: var(--ink-2); }

.atlas-idx-num {
  font-family: var(--sans);
  font-size: 0.58rem;
  letter-spacing: 0.2em;
  color: currentColor;
  opacity: 0.75;
}
.atlas-idx-year {
  font-family: var(--serif-display);
  font-size: 1rem;
  color: currentColor;
}
.atlas-idx.is-active .atlas-idx-year { color: var(--vermilion); }
.atlas-idx-city {
  font-family: var(--sans);
  font-size: 0.65rem;
  letter-spacing: 0.02em;
  color: currentColor;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* ---- Chapters stack: only active is visible ---- */
.atlas-chapters {
  position: relative;
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.2rem 0.6rem 1rem 0.1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}
.atlas-chapters::-webkit-scrollbar { width: 5px; }
.atlas-chapters::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 3px; }

.ach {
  display: none;
  animation: ach-fade 0.5s ease;
}
.ach.is-active { display: block; }

@keyframes ach-fade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.ach-head {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 1.1rem;
  row-gap: 0.4rem;
  align-items: baseline;
  margin-bottom: 1.4rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--rule);
  max-width: var(--measure);
}

.ach-num {
  grid-column: 1;
  grid-row: 1 / span 2;
  font-family: var(--sans);
  font-size: 0.95rem;
  letter-spacing: 0.28em;
  color: var(--vermilion);
  padding-top: 0.35rem;
  font-weight: 500;
}

.ach-year {
  grid-column: 2;
  font-family: var(--sans);
  font-size: 0.85rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.ach-title {
  grid-column: 2;
  font-family: var(--serif-display);
  font-weight: 500;
  font-size: clamp(1.7rem, 2.6vw, 2.25rem);
  line-height: 1.18;
  margin: 0;
  color: var(--ink);
}
.ach-title .han {
  display: inline-block;
  margin-left: 0.4rem;
  font-family: "Noto Serif SC", "Noto Serif TC", serif;
  font-weight: 600;
  font-size: 0.78em;
  color: var(--vermilion);
  opacity: 0.85;
  vertical-align: baseline;
}

.ach-quote {
  margin: 1rem 0 1.2rem;
  padding: 0 0 0 1rem;
  border-left: 2px solid var(--vermilion);
  font-style: italic;
  font-family: var(--serif-display);
  font-size: 1.12rem;
  line-height: 1.5;
  color: var(--ink-2);
  max-width: var(--measure);
}
.ach-quote cite {
  display: block;
  margin-top: 0.5rem;
  font-style: normal;
  font-family: var(--sans);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.ach-body {
  font-family: var(--serif-body);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--ink-2);
}
.ach-body p {
  margin: 0 0 0.9em;
}
.ach-body p:last-child { margin-bottom: 0; }

/* Photo frames */
.ach-photo {
  margin: 1.2rem 0;
}
.ach-photo .frame {
  position: relative;
  width: 100%;
  border: 1px solid var(--rule);
  background:
    repeating-linear-gradient(45deg, rgba(155,140,115,0.06) 0 12px, rgba(155,140,115,0.02) 12px 24px),
    rgba(240, 233, 220, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-align: center;
  white-space: pre-line;
  padding: 1rem;
  line-height: 1.6;
}
.ach-photo .frame::before { content: attr(data-label); }
.ach-photo .frame.wide   { aspect-ratio: 16 / 9; }
.ach-photo .frame.tall   { aspect-ratio: 3 / 4; }
.ach-photo .frame.square { aspect-ratio: 1 / 1; }

/* Real-image variant: suppresses the placeholder hatching + label */
.ach-photo .frame.has-image {
  padding: 0;
  background: var(--paper, #fff);
  overflow: hidden;
}
.ach-photo .frame.has-image::before { content: none; }
.ach-photo .frame.has-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ach-photo figcaption {
  margin-top: 0.5rem;
  font-family: var(--sans);
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.5;
}
.ach-photo figcaption strong {
  color: var(--ink-2);
  font-weight: 500;
  font-family: var(--serif-display);
  font-size: 0.88rem;
  letter-spacing: 0;
  display: block;
  margin-bottom: 0.15rem;
}

.ach-photo-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin: 1.2rem 0;
}
.ach-photo-pair .ach-photo { margin: 0; }

/* Stats for Port Hawkesbury */
.ach-stats {
  margin: 1.2rem 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7rem;
  padding: 1rem;
  background: rgba(251, 247, 238, 0.5);
  border: 1px solid var(--rule);
  border-radius: 2px;
}
.ach-stat {
  text-align: center;
}
.ach-stat .label {
  font-family: var(--sans);
  font-size: 0.6rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
.ach-stat .value {
  font-family: var(--serif-display);
  font-size: clamp(1.1rem, 1.6vw, 1.35rem);
  color: var(--ink);
  line-height: 1.2;
}
.ach-stat .arrow { color: var(--vermilion); margin: 0 0.15em; }

/* Stipend budget table for Ottawa chapter */
.ach-budget {
  width: auto;
  max-width: 100%;
  box-sizing: border-box;
  margin: 1.2rem 0 0.4rem;
  border-collapse: collapse;
  font-family: var(--serif);
  background: rgba(251, 247, 238, 0.5);
  border: 1px solid var(--rule);
  border-radius: 2px;
}
.ach-budget caption {
  caption-side: top;
  text-align: left;
  padding: 0 0 0.4rem;
  font-family: var(--sans);
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.ach-budget th,
.ach-budget td {
  padding: 0.4rem 1rem;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  white-space: nowrap;
}
.ach-budget tbody.expenses tr:first-child td {
  border-top: 2px solid var(--rule);
}
.ach-budget thead th {
  font-family: var(--sans);
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}
.ach-budget tbody td {
  font-size: 0.95rem;
}
.ach-budget tbody tr:last-child td {
  border-bottom: none;
}
.ach-budget tbody td:nth-child(2),
.ach-budget tbody td:nth-child(3) {
  font-family: var(--serif-display);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.ach-budget thead th:nth-child(2),
.ach-budget thead th:nth-child(3) {
  text-align: right;
}
.ach-budget-note {
  font-family: var(--sans);
  font-size: 0.7rem;
  color: var(--muted);
  margin: 0.4rem 0 1rem;
  font-style: italic;
  line-height: 1.5;
}

/* Bridge figure */
.ach-bridge {
  margin: 1.2rem 0;
}
.ach-bridge svg {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--rule);
  background: #fbf8f2;
}
.ach-bridge figcaption {
  margin-top: 0.5rem;
  font-family: var(--sans);
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.5;
}
.ach-bridge figcaption strong {
  color: var(--ink-2);
  font-weight: 500;
  font-family: var(--serif-display);
  font-size: 0.88rem;
  display: block;
  margin-bottom: 0.15rem;
}

/* =========================================================
   PAGER (prev / progress / next)
   ========================================================= */

.atlas-pager {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--rule);
  margin-top: 0.5rem;
}

.atlas-prev,
.atlas-next {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  border: 1px solid var(--rule);
  padding: 0.55rem 0.85rem;
  border-radius: 2px;
  font: inherit;
  cursor: pointer;
  color: var(--ink-2);
  transition: border-color 0.25s ease, color 0.25s ease, background 0.25s ease;
  min-width: 0;
}
.atlas-prev { justify-self: start; padding-left: 0.7rem; }
.atlas-next { justify-self: end;   padding-right: 0.7rem; }

.atlas-prev:hover:not(:disabled),
.atlas-next:hover:not(:disabled) {
  border-color: var(--vermilion);
  color: var(--ink);
  background: rgba(192, 57, 43, 0.04);
}
.atlas-prev:disabled,
.atlas-next:disabled {
  opacity: 0.35;
  cursor: default;
}

.atlas-prev svg,
.atlas-next svg { flex: 0 0 auto; color: var(--vermilion); }
.atlas-prev .lbl,
.atlas-next .lbl {
  font-family: var(--sans);
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  flex: 0 0 auto;
}
.atlas-prev .ttl,
.atlas-next .ttl {
  font-family: var(--serif-display);
  font-style: italic;
  font-size: 0.92rem;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 auto;
}
.atlas-next .ttl { text-align: right; }

.atlas-progress {
  font-family: var(--serif-display);
  font-size: 1rem;
  color: var(--ink-2);
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.atlas-current { color: var(--vermilion); font-weight: 500; }
.atlas-divider { color: var(--muted); margin: 0 0.2em; }
.atlas-total   { color: var(--muted); }

/* =========================================================
   Responsive — stack at narrow widths
   ========================================================= */

@media (max-width: 960px) {
  .atlas-body {
    min-height: 0;
  }
  .atlas-panel {
    min-height: 0;
  }
}

@media (max-width: 560px) {
  .atlas-frame { padding: 0.8rem; }
  .atlas-idx { min-width: 78px; padding: 0.4rem 0.5rem; }
  .atlas-idx-year { font-size: 0.95rem; }
  .atlas-idx-city { font-size: 0.62rem; }
  .atlas-prev .ttl, .atlas-next .ttl { display: none; }
  .atlas-photo-pair,
  .ach-photo-pair { grid-template-columns: 1fr; }
  .ach-stats { grid-template-columns: 1fr; }
}


