:root {
  --ink: #1c1b1a;
  --paper: #faf7f2;
  --panel: #ffffff;
  --border: #e2ddd3;
  --muted: #6b6459;
  --accent: #1565c0;
  --accent-ink: #ffffff;
  --overlay-scrim: rgba(0,0,0,0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #eeece6;
    --paper: #16151a;
    --panel: #1e1d24;
    --border: #34333d;
    --muted: #a29c8f;
    --accent: #7ab7f5;
    --accent-ink: #0b1620;
    --overlay-scrim: rgba(0,0,0,0.6);
  }
}

:root[data-theme="dark"] {
  --ink: #eeece6;
  --paper: #16151a;
  --panel: #1e1d24;
  --border: #34333d;
  --muted: #a29c8f;
  --accent: #7ab7f5;
  --accent-ink: #0b1620;
  --overlay-scrim: rgba(0,0,0,0.6);
}

* { box-sizing: border-box; }

button {
  font-family: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--paper);
  color: var(--ink);
}

.site-header {
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.site-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.theme-toggle {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

.site-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.mode-toggle {
  display: flex;
  gap: 0.3rem;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem;
  margin-bottom: 0.6rem;
}

.mode-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  cursor: pointer;
}

.mode-btn[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}

.timeline-disclaimer {
  margin: 0 0 0.5rem;
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.35;
}

.timeline-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.timeline-chip {
  flex-shrink: 0;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
}

.timeline-chip:hover {
  border-color: var(--accent);
}

.timeline-chip[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.timeline-caption {
  margin: 0 0 0.6rem;
  font-size: 0.82rem;
  line-height: 1.4;
}

#timeline-controls,
#browse-controls {
  margin-bottom: 0.5rem;
}

.layout {
  display: flex;
  min-height: 70vh;
}

.panel {
  width: 340px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--panel);
  max-height: 80vh;
  overflow: hidden;
}

.filter-block {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.search-wrap {
  position: relative;
  margin-bottom: 0.75rem;
}

.search-icon {
  position: absolute;
  left: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 0.55rem 0.7rem 0.55rem 2.1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-size: 0.88rem;
}

.search-input:focus-visible {
  border-color: var(--accent);
}

.search-input::-webkit-search-cancel-button {
  cursor: pointer;
}

.filter-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.filter-actions button {
  flex: 1;
  padding: 0.4rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  background: var(--paper);
  border-radius: 4px;
  cursor: pointer;
}

.filter-actions button:hover {
  background: var(--border);
}

.filter-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.filter-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.era-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.monument-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem;
  overflow-y: auto;
  flex: 1;
}

.monument-card {
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.5rem;
  cursor: pointer;
  background: var(--paper);
}

.monument-card:hover {
  border-color: var(--accent);
}

.monument-card.dimmed {
  opacity: 0.45;
}

.monument-card.dimmed:hover {
  opacity: 0.75;
}

.monument-card h3 {
  margin: 0 0 0.2rem;
  font-size: 0.9rem;
}

.monument-card .era-tag {
  font-size: 0.72rem;
  color: var(--muted);
}

.empty-state {
  padding: 1rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.map-wrap {
  position: relative;
  flex: 1;
}

.map {
  width: 100%;
  height: 100%;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: var(--paper);
  color: var(--muted);
  font-size: 0.85rem;
  z-index: 5;
}

.loading-overlay[hidden] {
  display: none;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.monument-marker {
  /* No "position" here: MapLibre's own .maplibregl-marker rule sets position:absolute on this
     same element (that's what makes its translate()-based placement work at all) — loading our
     stylesheet after maplibre-gl.css meant a "position: relative" here used to win the cascade
     and silently put every marker back into normal document flow, stacking them down the page. */
  width: 34px;
  height: 44px;
  cursor: pointer;
}

.monument-pin-svg {
  display: block;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5));
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.monument-marker.dimmed .monument-pin-svg {
  opacity: 0.3;
}

.monument-marker:hover .monument-pin-svg,
.monument-marker:focus-visible .monument-pin-svg {
  transform: scale(1.12);
  transform-origin: bottom center;
}

.monument-label {
  display: none;
  position: absolute;
  left: 100%;
  top: 6px;
  margin-left: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  text-shadow:
    -1px -1px 1px rgba(0,0,0,0.85),
    1px -1px 1px rgba(0,0,0,0.85),
    -1px 1px 1px rgba(0,0,0,0.85),
    1px 1px 1px rgba(0,0,0,0.85),
    0 0 4px rgba(0,0,0,0.85);
}

.monument-marker.show-label .monument-label {
  display: inline-block;
}

.detail-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 10;
}

.detail-overlay[hidden] {
  display: none;
}

.detail-card {
  position: relative;
  background: var(--panel);
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  border-radius: 8px;
  padding: 1.5rem;
}

.detail-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  font-size: 1.4rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
}

.detail-card h2 {
  margin: 0 0 0.25rem;
  font-size: 1.2rem;
}

.detail-card .era-tag {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.detail-card .address {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.detail-card img {
  width: 100%;
  border-radius: 6px;
  margin-bottom: 0.75rem;
}

.detail-card p {
  line-height: 1.5;
  font-size: 0.92rem;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.detail-actions .directions-link {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.85rem;
}

.secondary-btn {
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
}

.secondary-btn:hover {
  border-color: var(--accent);
}

.site-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--panel);
}

.site-footer a {
  color: var(--accent);
}

@media (max-width: 720px) {
  .layout {
    flex-direction: column;
  }
  .panel {
    width: 100%;
    max-height: 48vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .map-wrap {
    min-height: 50vh;
  }
}
