.atlas {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 100%;
  color: #502914;
  font-family: Georgia, serif;
}

.atlas-map {
  position: relative;
  isolation: isolate;
  flex: 1 0 auto;
  container-type: inline-size;
  min-height: min(400px, 36dvh);
  aspect-ratio: 2.2;
  background: linear-gradient(90deg, transparent 49.6%, #9a602a26 49.93%, #fff2ce85 50.13%, transparent 50.62%),
    url('assets/journal-map/paper.webp') center / 100% 100% no-repeat;
  filter: drop-shadow(0 2px 1px #55301775);
}

.atlas-key {
  position: absolute;
  z-index: 1;
  top: 4%;
  left: 3.3%;
  display: grid;
  gap: .34em;
  min-width: min(192px, 19cqw);
  padding: .51em .73em;
  outline: 1px solid #89633f9c;
  border-radius: 5px 8px 6px 4px;
  background: #edc58d66;
  font-size: clamp(.73rem, 1.93cqw, 1.36rem);
  font-weight: 700;
}

.atlas-key span { display: flex; align-items: center; gap: .48em; }
.atlas-overview {
  position: absolute;
  z-index: 1;
  top: 4%;
  right: 3.3%;
  padding: .44em .72em;
  border: 1px solid #89633f;
  border-radius: 6px;
  background: #f0ca94;
  color: #502914;
  font: 700 clamp(.73rem, 1.55cqw, 1.07rem)/1.1 Georgia, serif;
  cursor: pointer;
}
.atlas-overview:hover { background: #f8daad; }
.atlas-pin {
  display: inline-grid;
  place-items: center;
  width: .79em; height: .79em;
  margin: .03em .35em .12em .26em;
  border: .08em solid #713021;
  border-radius: 55% 55% 55% 7%;
  background: #c7492b;
  transform: rotate(-45deg);
  flex: none;
}
.atlas-pin::after { content: ''; width: .29em; height: .29em; border-radius: 50%; background: #f8d6a1; }
.atlas-key > span:nth-child(n+2)::before { content: ''; width: 1.52em; border-top: 3px solid #a84128; border-radius: 1px; }
.atlas-key > span:nth-child(3)::before { border-color: #8b6643; border-top-style: dashed; }
.atlas-social-key { display: none; }
.atlas-map[data-social-presence] .atlas-social-key {
  display: grid;
  grid-template-columns: auto auto;
  gap: .6em;
  padding-top: .34em;
  border-top: 1px solid #956a4277;
  font-size: .73em;
}
.atlas-social-key img { width: 1.5em; height: 1em; object-fit: contain; }
.atlas-trails { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.atlas-trails.is-narrow { display: none; }
.atlas-trail { fill: none; stroke: #7d5436; stroke-width: 3; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.atlas-trail.is-locked { stroke-dasharray: 4 6; opacity: .72; }
.atlas-trail.is-highlighted { stroke: #bd3924; stroke-width: 6; }

.atlas-node {
  position: absolute;
  top: var(--wide-y);
  left: var(--wide-x);
  display: grid;
  justify-items: center;
  align-content: center;
  width: min(184px, 16.7%);
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  transform: translate(-50%, -56%);
  cursor: pointer;
}

.atlas-node[hidden] { display: none; }
.atlas-node-art { position: relative; display: grid; place-items: end center; width: 96%; aspect-ratio: 1.65; }
.atlas-node-art > img {
  width: 100%; height: 100%; min-height: 0;
  object-fit: contain; object-position: center bottom;
  filter: drop-shadow(0 2px 1px #50321b66);
}
.atlas-node.is-locked .atlas-node-art > img { filter: saturate(.63) opacity(.80) drop-shadow(0 1px 1px #50321b5c); }
.atlas-node:is([data-location='gate'], [data-location='wattle']) .atlas-node-art { width: 64%; }
.atlas:not([data-workshop-district]) .atlas-node[data-location='workshop-crossing'] { width: min(140px, 12.5%); }
.atlas[data-workshop-district] .atlas-node:not([data-location='market'], [data-location='workshop-crossing']) .atlas-node-art { width: 74%; }
.atlas-social-marks {
  position: absolute;
  top: -.45em;
  right: -.28em;
  display: flex;
  gap: 2px;
  font-size: clamp(.67rem, 1.25cqw, .94rem);
  pointer-events: none;
}
.atlas-social-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .13em;
  min-width: 1.5em;
  padding: .18em .26em;
  border: 1px solid #e7c38a;
  border-radius: 5px 4px 6px 4px;
  background: #45563b;
  color: #fff1ce;
  box-shadow: 0 1px 3px #50321b86;
  font: 700 1em/1 'Trebuchet MS', sans-serif;
}
.atlas-social-badge.is-group { background: #34586e; }
.atlas-social-badge.is-signal { background: #864629; }
.atlas-social-badge img { width: 1.13em; height: 1em; object-fit: contain; }

.atlas-social-tip {
  --presence-anchor: var(--presence-wide-edge);
  --presence-gap: 5px;
  position: absolute;
  z-index: 2;
  bottom: calc(100% + var(--presence-gap));
  left: var(--presence-anchor);
  display: grid;
  gap: .28em;
  width: max-content;
  max-width: min(14rem, 48cqw);
  padding: .45em .55em;
  border: 1px solid #7e5430;
  border-radius: 5px 4px 7px 4px;
  background: #f1d3a2 var(--journal-paper) center / 100% 100%;
  box-shadow: 1px 2px 4px #59331c70;
  color: #502914;
  text-align: start;
  font: 600 clamp(.68rem, 1.22cqw, .87rem)/1.23 'Trebuchet MS', sans-serif;
  overflow-wrap: anywhere;
  transform: translateX(calc(-1 * var(--presence-anchor)));
  pointer-events: none;
  visibility: hidden;
}
.atlas-social-tip.is-wide-top { top: calc(100% + 5px); bottom: auto; }
.atlas-node[aria-current] .atlas-social-tip.is-wide-top { top: calc(100% + 2.25em); }
.atlas-node:has(.atlas-destination) .atlas-social-tip { --presence-gap: 2.65em; }
.atlas-social-tip strong, .atlas-social-details strong { display: block; color: #654125; }
.atlas-social-tip .atlas-social-signal, .atlas-social-details .atlas-social-signal { color: #842f20; }
.atlas-node:has(.atlas-social-tip):is(:hover, :focus-visible) { z-index: 3; }
.atlas-node:is(:hover, :focus-visible) .atlas-social-tip { visibility: visible; }
.atlas-social-details {
  display: grid;
  gap: .25em;
  margin: .45em 0;
  padding: .35em .55em;
  border-left: 2px solid #526b54;
  background: #e7c69275;
  font: 600 .80rem/1.22 'Trebuchet MS', sans-serif;
  overflow-wrap: anywhere;
}
.atlas-social-details[hidden] { display: none; }
.atlas-node-name {
  position: relative;
  max-width: 100%;
  min-width: 74%;
  padding: .38em .57em;
  overflow-wrap: anywhere;
  text-align: center;
  background: var(--journal-paper) center / 100% 100% no-repeat;
  filter: drop-shadow(0 2px 1px #77523180);
  font: 700 clamp(.73rem, 1.78cqw, 1.28rem)/1.02 Georgia, serif;
}

.atlas-node[aria-pressed='true'] .atlas-node-name, .atlas-node[aria-current] .atlas-node-name { box-shadow: inset 0 0 0 1.5px #a23d27; border-radius: 7px; }
.atlas-node-short-name { display: none; }
.atlas-node:hover .atlas-node-name { color: #963521; }
.atlas-node-here, .atlas-destination {
  position: absolute;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: .21em;
  padding: .28em .45em;
  text-align: center;
  font: 700 clamp(.62rem, 1.32cqw, .99rem)/1 Georgia, serif;
}
.atlas-node-here {
  top: calc(100% + 6px);
  color: #862e1f;
  background: var(--journal-paper) center / 100% 100% no-repeat;
  border: 1px solid #a45836;
  border-radius: 3px;
  font-size: clamp(.63rem, 1.75cqw, 1.19rem);
  transform: rotate(-5deg);
}
.atlas-destination {
  bottom: calc(100% + .84em);
  left: 34%;
  width: max-content;
  max-width: 7.4em;
  padding: .34em 1em .46em .56em;
  color: #fff0c7;
  background: #9b3824 var(--journal-red) center / 112% 127% no-repeat;
  border-top: 1px solid #7d3921;
  border-bottom: 1px solid #7d3921;
  font-size: clamp(.73rem, 1.83cqw, 1.24rem);
  transform: rotate(-8deg);
}
.atlas-destination::before {
  position: absolute;
  top: -.08em; left: -.15em;
  width: .2em; height: calc(100% + 2.2em);
  border: 1px solid #703a24;
  border-radius: .16em;
  background: linear-gradient(90deg, #93522b, #dd9a54 65%, #8d4726);
  content: '';
}
.atlas-destination::after {
  position: absolute;
  right: -1px; top: 0;
  width: .65em; height: 100%;
  background: #f3d29c;
  clip-path: polygon(100% 0, 100% 100%, 0 51%);
  content: '';
}

.atlas-place { flex: none; width: min(81%, 860px); margin-inline: auto; }
.atlas-detail {
  position: relative;
  background: var(--journal-paper) center / 100% 100% no-repeat;
  filter: drop-shadow(0 2px 1px #5e331d66);
}
.atlas-detail::before, .atlas-detail::after {
  position: absolute;
  top: 11px;
  width: 12px; height: 12px;
  border: 1px solid #6a4020;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 27%, #ffe097, #be7b33 48%, #8a471d 80%);
  box-shadow: 1px 1px 1px #76452480;
  pointer-events: none;
  content: '';
}
.atlas-detail::before { left: 13px; }
.atlas-detail::after { right: 13px; }
.atlas-route-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .52em;
  min-height: 66px;
  padding: .18em 1.45em;
  list-style: none;
  cursor: pointer;
  font: 600 clamp(.83rem, 1.66cqw, 1.24rem)/1.13 Georgia, serif;
}
.atlas-route-strip::-webkit-details-marker { display: none; }
.atlas-route-strip::after { content: '▾'; color: #884323; }
.atlas-detail[open] > .atlas-route-strip::after { content: '▴'; }
.atlas-route-strip img { width: 3.28em; height: 2.98em; flex: none; object-fit: contain; }
.atlas-route-strip > strong { padding-right: .6em; border-right: 1px solid #a2764a; }
.atlas-place-copy { padding: 4px 12px; }
.atlas-place-title, .atlas-exits { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; }
.atlas-place h3 { margin: 0; color: #642f1b; font: 700 1.08rem/1.14 Georgia, serif; }
.atlas-place p { margin: 3px 0 0; font: 500 .85rem/1.28 'Trebuchet MS', sans-serif; }
.atlas-status { color: #763d25; font: 800 .74rem/1.2 'Trebuchet MS', sans-serif; }
.atlas-place .atlas-route-hint { font-weight: 700; }
.atlas-exits { padding: 4px 12px 10px; }
.atlas-exit { padding: 4px 6px; border: 0; border-bottom: 1px solid #6f4b34; background: transparent; font-size: .8rem; }
.atlas-exit.is-locked { opacity: .84; border-bottom-style: dashed; }
.atlas-exit:hover { background: #b9743d26; }
.atlas-expanded-pager { display: none; }

@media (min-width: 761px) {
  .atlas-detail[open] { z-index: 2; }
  .atlas-expanded {
    position: absolute;
    inset: auto 0 calc(100% + 4px);
    max-height: 33dvh;
    overflow: auto;
    padding: 8px 12px 4px;
    border: 1px solid #966941;
    border-radius: 7px;
    background: #f2d5a4 url('assets/journal-map/paper.webp') center / 100% 100%;
    box-shadow: 0 3px 8px #462a195e;
  }
}

@media (min-width: 761px) and (max-height: 540px) {
  @container (max-width: 600px) {
    .atlas-node-name {
      padding-inline: .34em;
      overflow-wrap: normal;
      font-size: clamp(.59rem, 2.1cqw, .72rem);
    }
    .atlas-route-strip {
      min-height: 36px;
      padding-inline: 1.8em;
      font-size: clamp(.62rem, 2.25cqw, .78rem);
    }
    .atlas-route-strip img { width: 2.4em; height: 2.18em; }
    .atlas-detail::before, .atlas-detail::after { top: 8px; width: 8px; height: 8px; }
  }
}

@media (max-width: 760px) {
  .atlas { gap: 6px; }
  .atlas-map { min-height: 0; aspect-ratio: 400 / 630; overflow: clip; }
  .atlas[data-branch] .atlas-map { aspect-ratio: 400 / 962; }
  .atlas[data-workshop-district] .atlas-map { aspect-ratio: 400 / 535; }
  .atlas-key { top: 2%; }
  .atlas-overview { top: 2%; }
  .atlas-trails.is-wide { display: none; }
  .atlas-trails.is-narrow { display: block; height: calc(100% * 962 / 630); }
  .atlas[data-branch] .atlas-trails.is-narrow { height: 100%; }
  .atlas-node { top: calc(var(--narrow-y) * 962 / 630); left: var(--narrow-x); width: 29%; }
  .atlas:not([data-workshop-district]) .atlas-node[data-location='workshop-crossing'] { width: 29%; }
  .atlas[data-branch] .atlas-node { top: var(--narrow-y); }
  .atlas-node-name { font-size: .73rem; }
  .atlas-social-tip { --presence-anchor: var(--presence-narrow-edge); }
  .atlas-place { order: -1; width: 100%; }
  .atlas-route-strip img { width: 1.9em; }
  .atlas-destination { bottom: 92%; }
  .atlas-detail::before, .atlas-detail::after { content: none; }
}

@media (max-width: 760px), (max-height: 540px) {
  .atlas-social-tip,
  .atlas-social-tip.is-wide-top,
  .atlas-node[aria-current] .atlas-social-tip.is-wide-top {
    top: 17%;
    bottom: auto;
  }
  .atlas-social-tip span > strong { display: inline; }
}

@media (max-height: 540px) {
  .atlas-map[data-social-presence] .atlas-key {
    top: 2%;
    gap: .21em;
    padding: .4em .54em;
    font-size: clamp(.65rem, 1.7cqw, 1.08rem);
  }
  .atlas-map[data-social-presence] .atlas-social-key { padding-top: .21em; }
}

@media (hover: none) {
  .atlas-node[aria-pressed='true']:has(.atlas-social-tip) { z-index: 3; }
  .atlas-node[aria-pressed='true'] .atlas-social-tip { visibility: visible; }
}

@media (orientation: landscape) and (max-width: 1180px) and (max-height: 540px) {
  .atlas { height: 100%; min-height: 0; }
  .atlas .atlas-map { flex: 1 1 0; min-height: 0; aspect-ratio: auto; }
  .atlas .atlas-trails.is-wide { display: block; }
  .atlas .atlas-trails.is-narrow { display: none; }
  .atlas .atlas-node { top: var(--wide-y); left: var(--wide-x); width: min(16.7%, 130px); }
  .atlas:not([data-workshop-district]) .atlas-node[data-location='workshop-crossing'] { width: 13%; }
  .atlas .atlas-node-art { height: clamp(23px, 12.5dvh, 64px); aspect-ratio: auto; }
  .atlas .atlas-node-name {
    padding: .23em .3em;
    overflow-wrap: normal;
    font-size: clamp(10px, 1.72cqw, 14px);
  }
  .atlas:not([data-workshop-district]) [data-location='workshop-crossing'] .atlas-node-name { min-width: 0; font-size: clamp(9px, 1.4cqw, 12px); }
  .atlas-key, .atlas-map[data-social-presence] .atlas-key { gap: .2em; min-width: 0; padding: .25em .42em; font-size: clamp(10px, 1.55cqw, 13px); }
  .atlas-node-here { top: calc(100% + 2px); padding: .22em .33em; font-size: clamp(9px, 1.45cqw, 12px); white-space: nowrap; }
  .atlas-destination { bottom: calc(100% + .25em); font-size: clamp(10px, 1.5cqw, 13px); }
  .atlas .atlas-place { order: 0; width: min(93%, 660px); }
  .atlas .atlas-social-tip { --presence-anchor: var(--presence-wide-edge); }
  .atlas .atlas-route-strip { min-height: 29px; padding: 2px 1.7em; font-size: clamp(11px, 1.9cqw, 15px); }
  .atlas .atlas-route-strip img { width: 2em; height: 1.85em; }
  .atlas .atlas-detail::before, .atlas .atlas-detail::after { top: 8px; width: 7px; height: 7px; }
  #fieldbook[data-folio='map'] .book-page { overflow: clip; }
  .atlas-detail[open] { z-index: 4; }
  .atlas .atlas-expanded {
    position: absolute;
    inset: auto 0 calc(100% + 4px);
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    height: min(54dvh, 220px);
    max-height: none;
    overflow: clip;
    padding: 4px 7px;
    border: 1px solid #966941;
    border-radius: 6px;
    background: #f2d5a4 url('assets/journal-map/paper.webp') center / 100% 100%;
  }
  .atlas-expanded-pages {
    min-height: 0;
    padding-block: 3px;
    overflow: hidden;
    touch-action: none;
    column-count: 1;
    column-gap: 16px;
    column-fill: auto;
    overflow-wrap: anywhere;
  }
  .atlas-expanded .atlas-place-copy { padding: 0; display: contents; }
  .atlas-expanded .atlas-place-title { margin: 0 0 5px; break-after: avoid; }
  .atlas-expanded .atlas-social-details { break-inside: auto; }
  .atlas-expanded .atlas-social-details > span { break-inside: avoid; }
  .atlas-expanded .atlas-exits { padding: 3px 0; break-inside: avoid; }
  .atlas-expanded-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 26px;
    border-top: 1px solid #96694162;
    color: #6d371e;
    font: 700 11px/1 Georgia, serif;
  }
  .atlas-expanded-pager[data-single-page] { visibility: hidden; }
  .atlas-expanded-pager button {
    min-width: 39px;
    min-height: 23px;
    border: 1px solid #a07148;
    border-radius: 4px;
    color: inherit;
    background: #f5d59e;
    font: 700 17px/1 Georgia, serif;
  }
  .atlas-expanded-pager button:disabled { opacity: .45; }

  html[data-mobile-game] .atlas .atlas-route-strip { min-height: 44px; }
  html[data-mobile-game] .atlas .atlas-overview { min-height: 44px; }
  html[data-mobile-game] .atlas:has(.atlas-detail[open]) {
    display: grid;
    grid-template-columns: minmax(0, 1.68fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 8px;
  }
  html[data-mobile-game] .atlas:has(.atlas-detail[open]) .atlas-place {
    width: auto;
    min-width: 0;
    min-height: 0;
    margin: 0;
  }
  html[data-mobile-game] .atlas-detail[open] {
    height: 100%;
  }
  html[data-mobile-game] .atlas-detail[open] .atlas-route-strip {
    justify-content: flex-start;
    padding-inline: 9px;
  }
  html[data-mobile-game] .atlas-detail[open] .atlas-route-strip > strong { border-right: 0; }
  html[data-mobile-game] .atlas-detail[open] .atlas-route-strip > span { display: none; }
  html[data-mobile-game] .atlas-detail[open] .atlas-route-strip::after { margin-inline-start: auto; }
  html[data-mobile-game] .atlas-detail[open]::before,
  html[data-mobile-game] .atlas-detail[open]::after { content: none; }
  html[data-mobile-game] .atlas .atlas-expanded {
    position: absolute;
    inset: 44px 0 0;
    height: auto;
    min-height: 0;
  }
  html[data-mobile-game] .atlas:has(.atlas-detail[open]) .atlas-social-tip { visibility: hidden; }
  html[data-mobile-game] .atlas:has(.atlas-detail[open]) .atlas-node-name {
    padding-inline: 2px;
    font-size: clamp(9px, 2.35cqw, 12px);
    overflow-wrap: anywhere;
  }
  html[data-mobile-game] .atlas:has(.atlas-detail[open]) .atlas-node-full-name { display: none; }
  html[data-mobile-game] .atlas:has(.atlas-detail[open]) .atlas-node-short-name { display: inline; }
  html[data-mobile-game] .atlas:not([data-workshop-district]):has(.atlas-detail[open]) .atlas-node[data-location='workshop-crossing'] .atlas-node-name {
    overflow-wrap: anywhere;
  }
  html[data-mobile-game] .atlas-expanded .atlas-social-details {
    display: block;
    break-inside: auto;
  }
  html[data-mobile-game] .atlas-expanded .atlas-social-details > span { break-inside: auto; }
  html[data-mobile-game] .atlas-expanded-pager button {
    min-width: 44px;
    min-height: 44px;
  }
  html[data-mobile-game] .atlas-expanded-pager[data-single-page] { display: none; }
  html[data-mobile-game] .atlas-expanded .atlas-exits {
    display: block;
    break-inside: auto;
  }
  html[data-mobile-game] .atlas-expanded .atlas-exit {
    display: block;
    min-height: 44px;
    width: 100%;
    break-inside: avoid;
    text-align: start;
  }
}
