/* Relief plan in atlas style: dark water, light ground, translucent ink panels and white domes. */
.atlas {
  --atlas-ink: #0e171a;
  --atlas-panel: rgb(20 17 13 / 88%);
  --atlas-line: rgb(236 227 207 / 16%);
  --atlas-text: #ece3cf;
  --atlas-muted: #a99d87;
  --atlas-gold: #d4b46f;
  --atlas-halo: rgb(18 14 10 / 90%);
  --atlas-pin-scale: 1;
  background: var(--atlas-ink);
  color: var(--atlas-text);
  font: 15px/1.4 var(--atlas-ui);
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.atlas:active { cursor: grabbing; }
.atlas [data-era="califal"] { --era: #86afb6; }
.atlas [data-era="taifa"] { --era: #c9825a; }
.atlas [data-era="almohade"] { --era: #dcb162; }

.atlas.is-pointing { cursor: pointer; }

/* Relief: the flat base image laid on the ground until the 3D layer (walls, rooms, grid) is ready */
.atlas-relief { position: absolute; inset: 0; overflow: hidden; overflow: clip; pointer-events: none; }
.atlas-relief img { position: absolute; top: 0; left: 0; max-width: none; transform-origin: 0 0; }
.atlas-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; visibility: hidden; }
.atlas[data-relief="3d"] .atlas-canvas { visibility: visible; }
.atlas[data-relief="3d"] .atlas-relief { display: none; }

/* Labels and markers, kept at a constant size on screen */
.atlas-overlay { position: absolute; z-index: 1; inset: 0; pointer-events: none; }
.atlas-pins, .atlas-grid-labels { position: absolute; inset: 0; }
.atlas-grid-label { position: absolute; top: 0; left: 0; color: rgb(236 227 207 / 42%); font: 600 11px/1 var(--atlas-label); letter-spacing: .12em; }
.atlas-grid-column { translate: -50% calc(-100% - 5px); }
.atlas-grid-row { translate: calc(-100% - 7px) -50%; }

.atlas-label,
.atlas-entrance {
  position: absolute;
  top: 0;
  left: 0;
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 0 6px var(--atlas-halo), 0 0 2px var(--atlas-halo), 0 0 14px var(--atlas-halo);
}

.atlas-label { transition: opacity .3s; }
.atlas-label.is-off { opacity: .25; }
.atlas-label-name { display: block; margin-right: -.32em; color: var(--atlas-text); font: 600 var(--atlas-label-size, 19px)/1 var(--atlas-label); letter-spacing: .32em; }
.atlas-label-period { display: block; color: var(--era); font: italic 500 calc(var(--atlas-label-size, 19px) * .78)/1.3 var(--atlas-display); letter-spacing: .04em; }
.atlas-entrance { color: var(--atlas-gold); font: 600 12px/1 var(--atlas-label); letter-spacing: .24em; }
.atlas-entrance::before { display: block; width: 0; height: 0; margin: 0 auto 4px; border: 6px solid transparent; border-top: 0; border-bottom: 8px solid var(--atlas-gold); content: ''; }

.atlas-pin {
  position: absolute;
  z-index: var(--atlas-pin-order, 1);
  top: 0;
  left: 0;
  display: flex;
  width: 40px;
  height: 56px;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: -44px 0 0 -20px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--atlas-text);
  cursor: pointer;
  pointer-events: auto;
  transform-origin: 20px 44px;
  -webkit-tap-highlight-color: transparent;
}

.atlas-pin[hidden] { display: none; }
.atlas-pin:hover, .atlas-pin:focus-visible, .atlas-pin.is-active { z-index: 2000; }
.atlas-pin:focus-visible { outline: 2px solid var(--atlas-text); outline-offset: 2px; }
.atlas-pin-dome { width: 38px; height: 38px; flex: 0 0 auto; filter: drop-shadow(0 3px 2px rgb(0 0 0 / 55%)); transition: transform .2s cubic-bezier(.3, 1.6, .5, 1); }
.atlas-pin:hover .atlas-pin-dome,
.atlas-pin:focus-visible .atlas-pin-dome,
.atlas-pin.is-active .atlas-pin-dome { transform: translateY(-5px) scale(1.08); }
.atlas-pin-number {
  padding: 3px 6px 2px;
  border-radius: 999px;
  background: var(--era);
  box-shadow: 0 1px 0 rgb(255 255 255 / 35%) inset, 0 2px 4px rgb(0 0 0 / 50%);
  color: #16120e;
  font: 700 11px/1 var(--atlas-ui);
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
}
.atlas-pin.is-active .atlas-pin-number { background: var(--atlas-text); }
.atlas-pin-tip {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  padding: 5px 9px;
  border: 1px solid var(--atlas-line);
  border-radius: 6px;
  background: var(--atlas-panel);
  color: var(--atlas-text);
  font: 500 13px/1.2 var(--atlas-ui);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity .15s;
}
.atlas-pin:hover .atlas-pin-tip, .atlas-pin:focus-visible .atlas-pin-tip { opacity: 1; }
/* Leader from a marker moved aside (to avoid overlapping) back to its real position */
.atlas-pin-leader { position: absolute; z-index: -1; top: 44px; left: 20px; height: 1.5px; background: rgb(236 227 207 / 80%); box-shadow: 0 0 2px var(--atlas-halo); pointer-events: none; transform-origin: 0 50%; }
.atlas-pin-leader::after { position: absolute; top: -2.25px; right: -3px; width: 6px; height: 6px; border-radius: 50%; background: var(--era); box-shadow: 0 0 0 1.5px var(--atlas-text); content: ''; }

/* Floating panels */
.atlas-panel {
  position: absolute;
  z-index: 10;
  border: 1px solid var(--atlas-line);
  border-radius: 10px;
  background: var(--atlas-panel);
  box-shadow: 0 10px 30px rgb(0 0 0 / 35%);
  cursor: auto;
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  backdrop-filter: blur(10px) saturate(1.2);
}

.atlas-tools { top: 16px; right: 16px; display: flex; flex-direction: column; padding: 4px; }
.atlas-tools button { position: relative; display: grid; width: 40px; height: 40px; place-items: center; padding: 0; border: 0; border-radius: 7px; background: none; color: var(--atlas-text); font: 500 20px/1 var(--atlas-ui); cursor: pointer; }
.atlas-tools button:hover { background: rgb(236 227 207 / 9%); }
.atlas-tools button:focus-visible { outline: 2px solid var(--atlas-gold); outline-offset: -2px; }
.atlas-tools [data-atlas-action="fit"] { margin-top: 7px; }
.atlas-tools [data-atlas-action="fit"]::before { position: absolute; top: -4px; right: 6px; left: 6px; border-top: 1px solid var(--atlas-line); content: ''; }
.atlas-tools svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; }

.atlas-card {
  top: 16px;
  right: 72px;
  width: min(300px, calc(100% - 104px));
  max-height: calc(100% - 32px);
  padding: 18px 18px 12px;
  overflow-y: auto;
  opacity: 0;
  transform: translateX(12px);
  transition: transform .25s ease, opacity .25s ease, visibility 0s .25s;
  visibility: hidden;
}

.atlas-card.is-open { opacity: 1; transform: none; transition: transform .25s ease, opacity .25s ease; visibility: visible; }
.atlas-card-title { margin: 0 32px 10px 0; color: var(--atlas-text); font: 600 23px/1.1 var(--atlas-display); text-wrap: balance; }
.atlas-card-meta { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; margin: 0 0 16px; font-size: 13.5px; }
.atlas-card-meta dt { color: var(--atlas-muted); }
.atlas-card-meta dd { margin: 0; }
.atlas-card-era { display: inline-flex; align-items: center; gap: 6px; }
.atlas-card-era::before { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 2px; background: var(--era); content: ''; }
.atlas-card-go { display: flex; align-items: center; justify-content: center; padding: 12px 14px; border-radius: 8px; background: var(--atlas-gold); color: #18130d; font: 700 14.5px/1 var(--atlas-ui); text-decoration: none; }
.atlas-card-go:hover { filter: brightness(1.08); }
.atlas-card-go:focus-visible { outline: 2px solid var(--atlas-text); outline-offset: 2px; }
.atlas-card-steps { display: flex; justify-content: space-between; margin-top: 6px; }
.atlas-card-steps button { min-height: 32px; padding: 6px 4px; border: 0; background: none; color: var(--atlas-muted); font: 500 13px/1 var(--atlas-ui); cursor: pointer; }
.atlas-card-steps button:hover { color: var(--atlas-text); }
.atlas-card-close { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--atlas-muted); font: 22px/1 var(--atlas-ui); cursor: pointer; }
.atlas-card-close:hover { background: rgb(236 227 207 / 8%); color: var(--atlas-text); }

.atlas-legend { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); left: 12px; display: none; gap: 4px; padding: 5px; overflow-x: auto; }
.atlas-chip { display: flex; flex: 0 0 auto; align-items: center; gap: 9px; padding: 6px 10px 6px 8px; border: 0; border-radius: 7px; background: none; color: var(--atlas-text); font: inherit; text-align: left; cursor: pointer; }
.atlas-chip:hover { background: rgb(236 227 207 / 7%); }
.atlas-chip:focus-visible { outline: 2px solid var(--atlas-gold); outline-offset: -2px; }
.atlas-chip-swatch { width: 14px; height: 14px; flex: 0 0 auto; border-radius: 3px; background: var(--era); box-shadow: inset 0 0 0 1px rgb(0 0 0 / 25%); }
.atlas-chip-copy { display: flex; flex-direction: column; }
.atlas-chip-name { font: 700 14px/1.1 var(--atlas-ui); }
.atlas-chip-period { color: var(--atlas-muted); font: italic 500 13px/1.1 var(--atlas-display); }
.atlas-chip[aria-pressed="false"] .atlas-chip-name { color: var(--atlas-muted); text-decoration: line-through; }
.atlas-chip[aria-pressed="false"] .atlas-chip-swatch { background: transparent; box-shadow: inset 0 0 0 1.5px var(--era); }

.atlas-caption { position: absolute; z-index: 5; right: 18px; bottom: 14px; max-width: 46%; margin: 0; color: var(--atlas-muted); font: italic 500 13px/1.3 var(--atlas-display); text-align: right; text-shadow: 0 0 6px var(--atlas-halo), 0 0 2px var(--atlas-halo), 0 0 14px var(--atlas-halo); pointer-events: none; }
.atlas-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Without JavaScript: the relief and a list of the views */
.atlas-fallback { position: absolute; inset: 0; display: flex; flex-direction: column; }
.atlas-fallback .map-image-fallback { width: 100%; min-height: 0; flex: 1 1 auto; object-fit: contain; }
.atlas-fallback-list { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; padding: 12px 18px; background: var(--atlas-panel); font-size: 13px; list-style: none; }
.atlas-fallback-list a { color: var(--atlas-text); }

/* States driven by map-view.mjs */
.atlas:not([data-atlas-ready]) :is(.atlas-relief img, .atlas-canvas, .atlas-overlay, .atlas-tools, .atlas-legend, .atlas-caption) { visibility: hidden; }
.map-section[data-map-mode="compact"] .atlas { cursor: auto; touch-action: auto; }
.map-section[data-map-mode="compact"] :is(.atlas-overlay, .atlas-tools, .atlas-card, .atlas-legend, .atlas-caption),
.map-section[data-map-error] :is(.atlas-overlay, .atlas-tools, .atlas-card, .atlas-legend, .atlas-caption) { display: none; }

/* Full-screen map on phones: in-map period filter, no blur (cheaper while panning) and smaller domes */
@media (max-width: 680px), (orientation: landscape) and (max-height: 600px) and (max-width: 960px) {
  .atlas { --atlas-pin-scale: .86; --atlas-panel: rgb(20 17 13 / 94%); }
  .atlas-panel { -webkit-backdrop-filter: none; backdrop-filter: none; }
  .map-section[data-map-mode="expanded"] .atlas-legend { display: flex; }
  .atlas[data-card-open] .atlas-legend { visibility: hidden; }
  .atlas-caption, .atlas-grid-labels { display: none; }
  .atlas-tools { top: 12px; right: 12px; }
}

/* Card as a bottom sheet on narrow screens */
@media (max-width: 680px) {
  .atlas-card {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    max-height: 72%;
    padding: 8px 20px calc(14px + env(safe-area-inset-bottom, 0px));
    border-width: 1px 0 0;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
  }
  .atlas-card::before { display: block; width: 38px; height: 4px; margin: 0 auto 8px; border-radius: 2px; background: rgb(236 227 207 / 28%); content: ''; }
  .atlas-card.is-open { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .atlas *, .atlas *::before, .atlas *::after { transition: none !important; }
}
