/* ============================================================
   Scroll & Stone - Atlas: The Living Portolan
   ============================================================ */

.atlas-stage {
  --vellum: #F6EDD8;
  --vellum-hi: #FCF7EA;
  --vellum-deep: #EBDDBC;
  --ink: #2A2419;
  --ink-soft: #6A5B40;
  --coast: #8A6A3B;
  --techelet: #4A6FBE;
  --lapis: #24356E;
  --vermilion: #C8401F;
  --gold: #C9A227;
  --gold-hi: #F0DD9A;
  --gold-deep: #8C6E1D;
  position: relative;
  overflow: hidden;
  height: 100%;
  color: var(--ink);
  background:
    radial-gradient(ellipse 70% 50% at 40% 30%, rgba(255, 252, 240, 0.62), transparent 65%),
    linear-gradient(160deg, #F9F1DE, #F2E7CB 60%, #EDDFC0);
}

.atlas-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.15;
  mix-blend-mode: multiply;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="140" height="140"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves="2"/><feColorMatrix type="matrix" values="0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.5 0"/></filter><rect width="140" height="140" filter="url(%23n)"/></svg>');
}

.atlas-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse 36% 24% at 64% 44%, rgba(255, 250, 232, 0.5), transparent 70%);
  animation: atlas-sunwander 30s ease-in-out infinite alternate;
  mix-blend-mode: soft-light;
}

@keyframes atlas-sunwander {
  from { transform: translateX(-8vw); }
  to { transform: translateX(18vw); }
}

#atlasmap {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.atlas-vellum-sea { fill: transparent; }
.atlas-land {
  fill: url("#atlas-landwash");
  stroke: none;
  opacity: 0.96;
  pointer-events: none;
}
.atlas-coast {
  fill: none;
  stroke: var(--coast);
  stroke-width: 1.45;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  filter: url("#atlas-coast-soft");
  opacity: 0.78;
  pointer-events: none;
}
.atlas-rhumbs line {
  vector-effect: non-scaling-stroke;
  stroke-width: 0.75;
  opacity: 0.66;
  pointer-events: none;
}
.atlas-rhumbs .blue { stroke: rgba(74, 111, 190, 0.32); }
.atlas-rhumbs .brown { stroke: rgba(138, 106, 59, 0.26); }
.atlas-roses circle,
.atlas-roses path,
.atlas-roses line {
  vector-effect: non-scaling-stroke;
}
.atlas-rivers path {
  fill: none;
  stroke: rgba(74, 111, 190, 0.44);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.atlas-sea-name {
  font-family: var(--body);
  font-style: italic;
  font-size: 13px;
  letter-spacing: 4px;
  fill: rgba(74, 111, 190, 0.45);
}
.atlas-regname {
  font-family: var(--utility);
  letter-spacing: 5px;
  fill: rgba(106, 91, 64, 0.52);
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.7s ease;
}
.atlas-regname.on { opacity: 1; }

.atlas-flow {
  fill: none;
  stroke: var(--gold);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-dasharray: 6 5;
  opacity: 0;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
  transition: opacity 0.9s ease;
}
.atlas-flow-on {
  opacity: 0.82;
  pointer-events: stroke;
  animation: atlas-flowdraw 1.4s linear infinite;
}
@keyframes atlas-flowdraw {
  from { stroke-dashoffset: 24; }
  to { stroke-dashoffset: 0; }
}

.atlas-lamp {
  cursor: pointer;
  opacity: 0;
  transition: opacity 1.2s ease, filter 0.3s ease;
}
.atlas-lamp .halo,
.atlas-lamp .core {
  pointer-events: auto;
}
.atlas-lamp .core {
  animation: atlas-lamp-pulse 4.2s ease-in-out infinite;
}
.atlas-lamp:nth-child(3n) .core { animation-delay: 1.2s; }
.atlas-lamp:nth-child(3n+1) .core { animation-delay: 2.3s; }
.atlas-lamp.lit { opacity: 1; }
.atlas-lamp.dimmed { opacity: 0.16; }
.atlas-lamp.ember { opacity: 0.24; }
.atlas-lamp.ember .core { animation: none; filter: none; }
.atlas-lamp.search-hit {
  opacity: 1;
  filter: drop-shadow(0 0 14px rgba(240, 221, 154, 0.95));
}
.atlas-lamp.dimmed .halo,
.atlas-lamp.dimmed .core,
.atlas-lamp.ember:not(.lit):not(.search-hit) .halo,
.atlas-lamp.ember:not(.lit):not(.search-hit) .core,
.atlas-lamp:not(.lit):not(.search-hit):not(.ember) .halo,
.atlas-lamp:not(.lit):not(.search-hit):not(.ember) .core {
  pointer-events: none;
}
.atlas-lamp:focus-visible .core {
  stroke: var(--lapis);
  stroke-width: 2.2;
}
@keyframes atlas-lamp-pulse {
  0%, 100% { filter: drop-shadow(0 0 4px rgba(201, 162, 39, 0.55)); }
  50% { filter: drop-shadow(0 0 13px rgba(201, 162, 39, 0.95)); }
}
.atlas-label {
  font-family: var(--body);
  font-style: italic;
  fill: var(--ink-soft);
  pointer-events: none;
  opacity: 0;
  paint-order: stroke;
  stroke: var(--vellum);
  stroke-width: 0.17em;
  stroke-linejoin: round;
  transition: opacity 0.55s ease;
}
.atlas-label.on { opacity: 0.86; }
.atlas-label.search-hit { opacity: 1; fill: var(--lapis); }

.atlas-rubric,
.atlas-search-form,
.atlas-seals,
.atlas-filament,
.atlas-counter,
.atlas-cartouche,
.atlas-zoom,
.atlas-tooltip,
.atlas-card {
  z-index: 5;
}

.atlas-rubric {
  position: absolute;
  left: clamp(1.4rem, 4vw, 3.4rem);
  top: 8.5vh;
  max-width: 25rem;
  pointer-events: none;
}
.atlas-rubric-era {
  font-family: var(--utility);
  font-size: 0.7rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--gold-deep);
  margin: 0 0 0.18rem;
}
.atlas-rubric-range {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
  line-height: 1.05;
  color: var(--ink);
  margin: 0;
  letter-spacing: 0;
}
.atlas-rubric-note {
  font-family: var(--body);
  font-style: italic;
  font-size: 0.98rem;
  color: var(--ink-soft);
  margin-top: 0.35rem;
  line-height: 1.45;
}

.atlas-search-form {
  position: absolute;
  left: clamp(1.4rem, 4vw, 3.4rem);
  top: calc(8.5vh + 8.4rem);
  width: min(250px, calc(100vw - 2.8rem));
}
.atlas-search {
  width: 100%;
  background: transparent;
  border: 0;
  border-bottom: 1.5px solid rgba(106, 91, 64, 0.5);
  outline: none;
  font-family: var(--body);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--ink);
  padding: 0.3rem 0.1rem;
}
.atlas-search::placeholder { color: rgba(106, 91, 64, 0.65); }
.atlas-search:focus-visible {
  border-bottom-color: var(--gold-deep);
  outline: 2px solid rgba(201, 162, 39, 0.45);
  outline-offset: 5px;
}

.atlas-seals {
  position: absolute;
  left: 10%;
  bottom: 14.5vh;
  display: flex;
  gap: 0.9rem;
}
.atlas-seal {
  position: relative;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50% 48% 52% 50% / 50% 52% 48% 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.92rem;
  color: rgba(252, 247, 234, 0.92);
  background: radial-gradient(circle at 36% 30%, #B98A8A, #8A5252 55%, #5E3232);
  box-shadow: 0 2px 7px rgba(74, 52, 30, 0.35), inset 0 1px 2px rgba(255, 255, 255, 0.25);
  cursor: pointer;
  transition: transform 0.3s, box-shadow 0.3s, background 0.3s, color 0.3s;
}
.atlas-seal:hover { transform: scale(1.1); }
.atlas-seal[aria-pressed="true"] {
  background: radial-gradient(circle at 36% 30%, var(--gold-hi), var(--gold) 55%, var(--gold-deep));
  color: var(--ink);
  box-shadow: 0 0 14px rgba(201, 162, 39, 0.55), inset 0 1px 2px rgba(255, 255, 255, 0.4);
}
.atlas-seal::after {
  content: attr(data-label);
  position: absolute;
  top: -1.55rem;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  white-space: nowrap;
  font-family: var(--utility);
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}
.atlas-seal:hover::after,
.atlas-seal[aria-pressed="true"]::after,
.atlas-seal:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.atlas-seal:focus-visible,
.atlas-period-seg:focus-visible,
.atlas-zoom button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
}

.atlas-filament {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 7vh;
}
.atlas-thread {
  position: relative;
  height: 44px;
}
.atlas-thread::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 21px;
  height: 3px;
  background: linear-gradient(90deg, transparent, rgba(140, 110, 29, 0.5) 4%, rgba(140, 110, 29, 0.5) 96%, transparent);
}
.atlas-period-seg {
  position: absolute;
  top: 17px;
  height: 11px;
  border: 0;
  border-radius: 999px;
  background: rgba(201, 162, 39, 0.28);
  cursor: pointer;
  padding: 0;
  transition: background 0.35s, box-shadow 0.35s, transform 0.35s;
}
.atlas-period-seg:hover { background: rgba(201, 162, 39, 0.55); }
.atlas-period-seg.lit {
  top: 16px;
  height: 13px;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold) 30%, var(--gold-hi) 50%, var(--gold) 70%, var(--gold-deep));
  box-shadow: 0 0 16px rgba(240, 221, 154, 0.75);
}
.atlas-period-seg span {
  position: absolute;
  top: -1.45rem;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-family: var(--utility);
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.atlas-period-seg:hover span,
.atlas-period-seg.lit span,
.atlas-period-seg:focus-visible span { opacity: 0.9; }
.atlas-bead {
  position: absolute;
  top: 21px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 30%, var(--gold-hi), var(--gold) 55%, var(--gold-deep));
  box-shadow: 0 0 6px rgba(201, 162, 39, 0.4);
  pointer-events: none;
}
.atlas-bead span {
  position: absolute;
  top: 11px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--utility);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  opacity: 0.7;
  white-space: nowrap;
}
.atlas-counter {
  position: absolute;
  left: 10%;
  bottom: 3vh;
  margin: 0;
  font-family: var(--body);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.atlas-cartouche {
  position: absolute;
  right: clamp(1.4rem, 3vw, 2.8rem);
  bottom: calc(7vh + 4.4rem);
  padding: 0.9rem 1.1rem 0.8rem;
  max-width: 215px;
  border: 1.5px solid rgba(138, 106, 59, 0.55);
  outline: 1px solid rgba(138, 106, 59, 0.3);
  outline-offset: 3px;
  background: rgba(252, 247, 234, 0.55);
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.atlas-cartouche::before {
  content: "❧";
  position: absolute;
  top: -13px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--vellum);
  padding: 0 0.5rem;
  color: var(--gold-deep);
  font-size: 1rem;
}
.atlas-cartouche-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.3rem 0;
  font-family: var(--utility);
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}
.atlas-legend-dot {
  border-radius: 50%;
  flex: 0 0 auto;
  background: radial-gradient(circle at 35% 30%, var(--gold-hi), var(--gold) 55%, var(--gold-deep));
}
.atlas-dot-great { width: 13px; height: 13px; }
.atlas-dot-mid { width: 9px; height: 9px; }
.atlas-dot-ember { width: 9px; height: 9px; opacity: 0.25; }
.atlas-legend-flow {
  stroke: var(--gold);
  stroke-width: 1.8;
  fill: none;
  stroke-dasharray: 4 3;
}

.atlas-zoom {
  position: absolute;
  right: clamp(1.4rem, 3vw, 2.8rem);
  top: calc(8.5vh + 1rem);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.atlas-zoom button {
  width: 2.15rem;
  height: 2.15rem;
  border: 1px solid rgba(138, 106, 59, 0.5);
  background: rgba(252, 247, 234, 0.58);
  color: var(--ink);
  font-family: var(--utility);
  font-size: 1rem;
  cursor: pointer;
  backdrop-filter: blur(2px);
}

.atlas-tooltip,
.atlas-card {
  position: absolute;
  font-family: var(--body);
  color: var(--ink);
  background: linear-gradient(165deg, #FAF3E0, #EFE2C2);
  clip-path: polygon(0 3%, 4% 0, 96% 1%, 100% 6%, 99% 95%, 95% 100%, 3% 99%, 0 94%);
  box-shadow: 4px 6px 20px rgba(74, 52, 30, 0.35);
}
.atlas-tooltip {
  width: 250px;
  z-index: 8;
  padding: 0.85rem 1rem;
  font-size: 0.88rem;
  font-style: italic;
  line-height: 1.45;
  opacity: 0;
  transform: scale(0.92) translateY(4px);
  transform-origin: left center;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}
.atlas-tooltip.show {
  opacity: 1;
  transform: scale(1) translateY(0);
}
.atlas-tooltip strong {
  display: block;
  font-family: var(--display);
  font-style: normal;
  font-size: 1.02rem;
  color: var(--lapis);
  margin-bottom: 0.15rem;
}
.atlas-card {
  z-index: 9;
  width: min(340px, 86vw);
  padding: 1rem 1.1rem 1.05rem;
  font-size: 0.92rem;
  line-height: 1.45;
}
.atlas-card[hidden] { display: none; }
.atlas-card-close {
  position: absolute;
  top: 0.45rem;
  right: 0.65rem;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 1.15rem;
}
.atlas-card-name {
  margin: 0 1.5rem 0.35rem 0;
  font-family: var(--display);
  font-weight: 900;
  color: var(--lapis);
  font-size: 1.25rem;
}
.atlas-card-note {
  margin: 0 0 0.65rem;
  font-style: italic;
  color: var(--ink);
}
.atlas-card-list {
  list-style: none;
  padding: 0;
  margin: 0.6rem 0 0;
}
.atlas-card-list li { margin: 0.38rem 0; }
.atlas-card-list a {
  color: var(--vermilion);
  text-decoration: none;
  border-bottom: 1px solid rgba(201, 162, 39, 0.48);
}
.atlas-card-list a:hover,
.atlas-card-list a:focus-visible { border-bottom-color: var(--vermilion); }
.atlas-card-empty {
  margin: 0;
  color: var(--ink-soft);
  font-style: italic;
}
.atlas-card-draft {
  color: var(--ink-soft);
  font-style: italic;
}

@media (max-width: 760px) {
  .atlas-rubric {
    top: 3.5vh;
    left: 1rem;
    max-width: min(22rem, calc(100vw - 2rem));
  }
  .atlas-rubric-range { font-size: 1.75rem; }
  .atlas-rubric-note { font-size: 0.88rem; max-width: 18rem; }
  .atlas-search-form {
    top: calc(3.5vh + 7.1rem);
    left: 1rem;
    width: min(220px, calc(100vw - 2rem));
  }
  .atlas-seals {
    left: 0;
    right: 0;
    bottom: 15vh;
    gap: 0.7rem;
    overflow-x: auto;
    padding: 1.8rem 1rem 0.25rem;
    scrollbar-width: none;
  }
  .atlas-seals::-webkit-scrollbar { display: none; }
  .atlas-filament {
    left: 1rem;
    right: 1rem;
    bottom: 7.6vh;
  }
  .atlas-cartouche {
    right: 0.9rem;
    bottom: 27vh;
    max-width: 158px;
    padding: 0.65rem 0.75rem;
  }
  .atlas-cartouche-row {
    font-size: 0.56rem;
    gap: 0.45rem;
  }
  .atlas-counter {
    left: 1rem;
    right: 1rem;
    bottom: 3vh;
    font-size: 0.82rem;
  }
  .atlas-zoom {
    top: 1rem;
    right: 0.9rem;
  }
  .atlas-tooltip {
    position: fixed;
    left: 1rem !important;
    right: 1rem;
    bottom: 1rem;
    top: auto !important;
    width: auto;
    transform-origin: bottom center;
  }
  .atlas-card {
    position: fixed;
    left: 1rem !important;
    right: 1rem;
    bottom: 1rem;
    top: auto !important;
    width: auto;
    max-height: 48vh;
    overflow-y: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .atlas-stage::before,
  .atlas-lamp .core,
  .atlas-flow-on {
    animation: none;
  }
  .atlas-lamp,
  .atlas-label,
  .atlas-flow,
  .atlas-regname,
  .atlas-period-seg,
  .atlas-seal,
  .atlas-tooltip {
    transition: none;
  }
  .atlas-flow-on { stroke-dashoffset: 0; }
}

@media (hover: none) and (pointer: coarse) {
  .atlas-stage::before,
  .atlas-lamp .core,
  .atlas-flow-on {
    animation: none;
  }

  .atlas-lamp,
  .atlas-label,
  .atlas-flow,
  .atlas-regname,
  .atlas-period-seg,
  .atlas-seal,
  .atlas-tooltip {
    transition: none;
  }

  .atlas-flow-on {
    stroke-dashoffset: 0;
  }
}

html.stable-map .atlas-stage::before,
html.stable-map .atlas-lamp .core,
html.stable-map .atlas-flow-on {
  animation: none !important;
}

html.stable-map .atlas-stage::after {
  mix-blend-mode: normal;
  opacity: 0.08;
}

html.stable-map .atlas-stage::before {
  mix-blend-mode: normal;
  opacity: 0.32;
}

html.stable-map .atlas-coast,
html.stable-map .atlas-lamp.search-hit {
  filter: none !important;
}

html.stable-map .atlas-lamp,
html.stable-map .atlas-label,
html.stable-map .atlas-flow,
html.stable-map .atlas-regname,
html.stable-map .atlas-period-seg,
html.stable-map .atlas-seal,
html.stable-map .atlas-tooltip {
  transition: none !important;
}

html.stable-map .atlas-flow-on {
  stroke-dashoffset: 0;
}
