/*
 * NearPast map-first shell — 2026-08-26
 * The map and the ranked list are separate destinations. This final layer is
 * intentionally reversible and leaves the earlier visual system intact.
 */

:root {
  --near-nav-height: 76px;
  --near-page-gutter: clamp(16px, 4vw, 40px);
}

.app-shell {
  min-height: 100dvh;
  padding: 0 0 calc(var(--near-nav-height) + env(safe-area-inset-bottom));
}

.topbar {
  height: var(--topbar);
  min-height: var(--topbar);
}

#main-content {
  min-height: calc(100dvh - var(--topbar) - var(--near-nav-height) - env(safe-area-inset-bottom));
}

html[data-tab="map"],
html[data-tab="map"] body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

html[data-tab="map"] .app-shell,
html[data-tab="map"] #main-content,
html[data-tab="map"] .map-panel,
html[data-tab="map"] .map-screen {
  height: calc(100dvh - var(--topbar) - var(--near-nav-height) - env(safe-area-inset-bottom));
  min-height: 0;
}

.map-panel,
.map-screen {
  position: relative;
  overflow: hidden;
}

.map-screen .field-plot {
  position: absolute;
  inset: 0;
  top: 0;
  overflow: clip;
  width: 100%;
  min-width: 0;
  height: 100%;
  max-width: none;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transform: none;
}

.map-screen .field-plot::before {
  border: 0;
  background:
    linear-gradient(rgba(45, 49, 42, 0.048) 1px, transparent 1px),
    linear-gradient(90deg, rgba(45, 49, 42, 0.048) 1px, transparent 1px),
    radial-gradient(circle at 50% 50%, transparent 62%, rgba(35, 38, 32, 0.2) 100%);
  background-size: 32px 32px, 32px 32px, auto;
}

.map-screen .current-point {
  pointer-events: none;
}

.map-head-overlay,
.map-location-overlay,
.era-filter--map,
.map-screen .map-controls,
.map-screen .map-utility-bar {
  z-index: 24;
}

.map-head-overlay {
  position: absolute;
  top: 18px;
  left: 20px;
  max-width: min(38rem, calc(100% - 560px));
  padding: 13px 16px 14px;
  border: 1px solid rgba(61, 62, 54, 0.3);
  color: var(--ink);
  background: rgba(246, 243, 234, 0.9);
  border-radius: 12px 12px 12px 4px;
  box-shadow: 0 3px 0 rgba(119, 113, 98, 0.36), 0 12px 28px rgba(36, 37, 32, 0.16);
  backdrop-filter: blur(13px) saturate(1.08);
  pointer-events: none;
}

.map-head-overlay::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 4px;
  background: var(--signal);
  content: "";
}

.map-head-overlay h1 {
  margin-top: 3px;
  font-family: var(--font-display);
  font-size: clamp(20px, 2.3vw, 30px);
  font-weight: 780;
  letter-spacing: -0.045em;
  line-height: 1.18;
  text-wrap: balance;
}

.map-head-overlay .map-status-line {
  margin-top: 7px;
}

.map-location-overlay {
  position: absolute;
  bottom: 20px;
  left: 20px;
  display: grid;
  width: min(420px, calc(100% - 530px));
  min-width: 340px;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "where action"
    "privacy privacy";
  align-items: center;
  gap: 8px 14px;
  margin: 0;
  padding: 13px 14px;
  border-radius: 12px 12px 12px 4px;
}

.map-location-overlay .location-card__top { grid-area: where; min-width: 0; }
.map-location-overlay .location-button { grid-area: action; min-height: 48px; margin: 0; padding-inline: 14px; }
.map-location-overlay .privacy-note { grid-area: privacy; margin: 0; }
.map-location-overlay .location-label { font-size: 14px; }
.map-location-overlay .location-detail { font-size: 12px; }

.era-filter--map {
  position: absolute;
  top: 18px;
  right: 20px;
  width: min(500px, calc(100% - 520px));
  margin: 0;
  padding: 7px;
  border-radius: 13px;
  box-shadow: 0 3px 0 rgba(119, 113, 98, 0.36), 0 12px 28px rgba(36, 37, 32, 0.14);
  backdrop-filter: blur(13px) saturate(1.08);
}

.era-filter--map .era-options {
  min-height: 50px;
  padding: 3px;
}

.era-filter--map .era-options label { flex-basis: 70px; }
.era-filter--map .era-options span { min-height: 42px; }

.era-options span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.era-options span::before {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border: 1.5px solid rgba(255, 255, 255, 0.88);
  background: var(--era-pin-color, var(--ink-soft));
  border-radius: 50% 50% 50% 0;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--era-pin-color, var(--ink-soft)) 78%, #1b1d1b);
  content: "";
  transform: rotate(-45deg);
}

.era-options label:has(input[value="all"]) { --era-pin-color: conic-gradient(var(--ancient) 0 25%, var(--medieval) 0 50%, var(--early-modern) 0 75%, var(--modern) 0); }
.era-options label:has(input[value="ancient"]) { --era-pin-color: var(--ancient); }
.era-options label:has(input[value="medieval"]) { --era-pin-color: var(--medieval); }
.era-options label:has(input[value="early-modern"]) { --era-pin-color: var(--early-modern); }
.era-options label:has(input[value="modern"]) { --era-pin-color: var(--modern); }

.map-screen .map-controls {
  right: 20px;
  bottom: 20px;
  left: auto;
  grid-template-columns: 46px 46px 72px 46px;
  transform: none;
}

.map-screen .map-controls .map-zoom-value {
  font-family: var(--font-numeric);
  font-size: 12px;
  letter-spacing: -0.025em;
}

.map-screen .map-utility-bar {
  right: 20px;
  bottom: 78px;
  left: auto;
  width: auto;
  max-width: min(660px, calc(100% - 40px));
}

.map-marker {
  z-index: 7;
  display: block;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  height: 44px;
  gap: 0;
  padding: 0;
  border: 0;
  background: transparent !important;
  border-radius: 0;
  box-shadow: none;
  animation: none !important;
  transform: translate(-50%, -100%);
  transform-origin: 50% 100%;
  transition: opacity 100ms linear;
}

.map-marker:hover,
.map-marker:focus-visible {
  z-index: 10;
  background: transparent !important;
  box-shadow: none;
  transform: translate(-50%, -100%);
}

.map-marker:focus-visible {
  outline: none;
}

.map-marker.is-nearest,
.map-marker.is-compact {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.map-marker .map-pin-shape,
.map-marker.is-nearest .map-pin-shape,
.map-marker.is-compact .map-pin-shape {
  position: absolute;
  bottom: 4px;
  left: 50%;
  display: block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.96);
  background: var(--marker);
  border-radius: 50% 50% 50% 0;
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--marker) 76%, #20231f),
    -3px 5px 9px rgba(31, 34, 30, 0.25);
  transform: translateX(-50%) rotate(-45deg);
  transform-origin: 50% 50%;
  transition: filter 120ms var(--ease-direct), transform 120ms var(--ease-direct);
}

.map-marker .map-pin-shape::after {
  position: absolute;
  inset: 5px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  content: "";
}

.map-marker:hover .map-pin-shape,
.map-marker:focus-visible .map-pin-shape {
  filter: saturate(1.12) brightness(1.04);
  transform: translateX(-50%) rotate(-45deg) scale(1.12);
}

.map-marker:focus-visible .map-pin-shape {
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.98),
    0 0 0 5px var(--focus),
    -3px 5px 9px rgba(31, 34, 30, 0.25);
}

.map-marker.is-new .map-pin-shape {
  animation: map-pin-shape-once 220ms var(--ease-enter) both;
}

.map-marker.is-outside { opacity: 0; pointer-events: none; }

.kind-badge {
  display: inline-flex;
  min-height: 29px;
  align-items: center;
  padding: 3px 9px;
  border: 1px solid rgba(92, 71, 43, 0.2);
  color: #5e4527;
  background: rgba(226, 207, 170, 0.5);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.015em;
}

.detail-meta .kind-badge {
  border-color: color-mix(in srgb, var(--era-color, var(--era)) 20%, rgba(92, 71, 43, 0.2));
  background: rgba(255, 255, 255, 0.42);
}

.list-page {
  width: min(1040px, 100%);
  min-height: calc(100dvh - var(--topbar) - var(--near-nav-height));
  margin-inline: auto;
  padding: clamp(34px, 6vw, 76px) var(--near-page-gutter) 120px;
}

.list-intro {
  display: grid;
  width: 100%;
  max-width: none;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 420px);
  grid-template-areas:
    "eyebrow nearest"
    "context nearest"
    "title nearest";
  align-items: end;
  gap: 4px 36px;
  margin-bottom: 26px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--line-strong);
}

.list-intro .eyebrow { grid-area: eyebrow; }
.list-intro #results-context { grid-area: context; }
.list-intro #results-title { grid-area: title; margin: 4px 0 0; }
.list-intro .nearest-glance { grid-area: nearest; width: 100%; margin: 0; }

.era-filter--list {
  position: sticky;
  z-index: 18;
  top: calc(var(--topbar) + 10px);
  margin: 0 0 28px;
  background: rgba(244, 241, 232, 0.94);
  backdrop-filter: blur(16px);
}

.bottom-nav {
  position: fixed;
  z-index: 70;
  top: auto;
  right: auto;
  bottom: max(8px, env(safe-area-inset-bottom));
  left: 50%;
  width: min(680px, calc(100% - 24px));
  height: 68px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: 1fr;
  border-radius: 18px;
  animation: none;
  transform: translateX(-50%);
}

.bottom-nav::before {
  top: 5px;
  right: auto;
  bottom: 5px;
  left: 5px;
  width: calc((100% - 10px) / 4);
  height: auto;
  transform: translateX(0);
}

.bottom-nav:has(#list-tab.is-active)::before { transform: translateX(100%); }
.bottom-nav:has(#saved-tab.is-active)::before { transform: translateX(200%); }
.bottom-nav:has(#about-tab.is-active)::before { transform: translateX(300%); }

.nav-item {
  min-height: 58px;
}

.nav-item svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

@keyframes map-pin-shape-once {
  from { opacity: 0; transform: translateX(-50%) rotate(-45deg) scale(0.7); }
  to { opacity: 1; transform: translateX(-50%) rotate(-45deg) scale(1); }
}

@media (max-width: 920px) {
  .map-head-overlay {
    max-width: calc(100% - 380px);
  }

  .era-filter--map {
    width: 350px;
  }

  .map-location-overlay {
    width: min(400px, calc(100% - 300px));
    min-width: 330px;
  }

  .map-screen .map-utility-bar .map-gesture { display: none; }
}

@media (max-width: 719px) {
  :root {
    --near-nav-height: 72px;
    --topbar: 70px;
  }

  .topbar { padding-inline: 12px; }
  .brand-mark { width: 42px; height: 42px; }
  .brand-copy small { display: none; }
  .language-picker select { width: 82px; }

  .map-head-overlay {
    top: 10px;
    right: 12px;
    left: 12px;
    max-width: none;
    padding: 10px 12px 11px;
  }

  .map-head-overlay h1 { font-size: 21px; }
  .map-head-overlay .section-kicker { font-size: 12px; }
  .map-head-overlay .map-status-line { gap: 4px 9px; font-size: 12px; }

  .era-filter--map {
    top: 116px;
    right: 12px;
    left: 12px;
    width: auto;
    padding: 4px;
    border-radius: 11px;
  }

  .era-filter--map .era-options {
    min-height: 45px;
    gap: 2px;
    padding: 2px;
  }

  .era-filter--map .era-options label { flex: 1 0 58px; }
  .era-filter--map .era-options span { min-height: 39px; padding-inline: 5px; font-size: 12px; }

  .map-location-overlay {
    right: 12px;
    bottom: 74px;
    left: 12px;
    width: auto;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr) 48px;
    gap: 6px 8px;
    padding: 10px 11px;
  }

  .map-location-overlay .location-status-icon { width: 35px; height: 35px; }
  .map-location-overlay .section-kicker { display: none; }
  .map-location-overlay .location-label { margin: 0; font-size: 13px; }
  .map-location-overlay .location-detail { margin: 1px 0 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .map-location-overlay .location-button { width: 48px; min-width: 48px; min-height: 46px; padding: 0; }
  .map-location-overlay .location-button span { display: none; }
  .map-location-overlay .privacy-note { display: none; }

  .map-screen .map-controls {
    right: 12px;
    bottom: 12px;
    grid-template-columns: 44px 44px 68px 44px;
  }

  .map-screen .map-controls button { min-width: 44px; min-height: 44px; }

  .map-screen .map-utility-bar {
    right: auto;
    bottom: 13px;
    left: 12px;
    display: flex;
    width: auto;
    min-height: 40px;
    max-width: calc(100% - 220px);
    padding: 6px 9px;
  }

  .map-screen .map-utility-bar .map-gesture,
  .map-screen .map-route-note,
  .map-screen .map-provenance i { display: none; }
  .map-screen .map-provenance { justify-content: flex-start; white-space: nowrap; }

  .direction--north { top: 210px; }
  .direction--south { bottom: 190px; }
  .direction--east,
  .direction--west { top: 52%; }

  .current-point b { top: calc(100% + 8px); }

  .list-page {
    padding: 34px 16px 112px;
  }

  .list-intro {
    grid-template-columns: 1fr;
    grid-template-areas: "eyebrow" "context" "title" "nearest";
    gap: 5px;
    margin-bottom: 18px;
    padding-bottom: 20px;
  }

  .list-intro .nearest-glance { margin-top: 14px; }
  .era-filter--list { top: calc(var(--topbar) + 6px); margin-inline: -4px; }

  .bottom-nav {
    bottom: max(6px, env(safe-area-inset-bottom));
    width: calc(100% - 16px);
    height: 62px;
    border-radius: 16px;
  }

  .nav-item { min-height: 52px; font-size: 12px; }
  .nav-item svg { width: 19px; height: 19px; }
}

@media (max-width: 380px) {
  .map-head-overlay h1 { font-size: 19px; }
  .map-head-overlay .map-density { display: none; }
  .era-filter--map { top: 116px; }
  .map-location-overlay .location-status-icon { display: none; }
  .map-location-overlay .location-card__top { grid-template-columns: 1fr; }
  .map-location-overlay .location-label { font-size: 12px; }
  .map-screen .map-utility-bar { display: none; }
  .map-screen .map-controls { left: 50%; right: auto; transform: translateX(-50%); }
}

.source-row > div {
  min-width: 0;
  flex: 1 1 auto;
}

.source-link-list {
  display: grid;
  gap: 7px;
}

.source-row .source-link-list a {
  width: 100%;
  min-height: 44px;
  padding: 8px 11px;
  border: 1px solid color-mix(in srgb, var(--era-color) 24%, var(--line));
  background: color-mix(in srgb, var(--era-soft) 44%, var(--surface));
  border-radius: 8px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  text-decoration: none;
}

.source-row .source-link-list a:hover,
.source-row .source-link-list a:focus-visible {
  border-color: var(--era-color);
  text-decoration: underline;
}

@media (max-width: 520px) {
  .source-row { flex-direction: column; }
  .source-row > small { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  .map-marker,
  .map-marker .map-pin-shape,
  .map-marker.is-new .map-pin-shape,
  .bottom-nav::before { animation: none !important; transition: none !important; }
}

@media (forced-colors: active) {
  .map-head-overlay,
  .map-location-overlay,
  .era-filter--map { border: 1px solid CanvasText; background: Canvas; box-shadow: none; }
  .map-marker:focus-visible { outline: 3px solid CanvasText; outline-offset: -4px; }
}
