:root {
  --paper: #f1ece3;
  --ink: #171310;
  --muted: #5f554b;
  --card: #fffdf8;
  --line: #ddd0bc;
  --accent: #1f5f4a;
  --accent-2: #8c5f2e;
  --shadow: 0 6px 20px rgba(34, 24, 12, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Source Serif 4", Georgia, serif;
  background:
    radial-gradient(circle at 0% 0%, #e7dbc8 0%, transparent 30%),
    radial-gradient(circle at 100% 100%, #e8ddce 0%, transparent 35%),
    var(--paper);
}

.container {
  width: min(1200px, calc(100% - 2rem));
  margin: 1.5rem auto 3rem;
}

.hero {
  margin-bottom: 1rem;
}

h1 {
  margin: 0;
  font-size: clamp(1.7rem, 2vw + 1rem, 2.4rem);
}

.toolbar {
  position: sticky;
  top: 0.5rem;
  z-index: 10;
  background: rgba(241, 236, 227, 0.9);
  backdrop-filter: blur(4px);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem;
  margin-bottom: 1rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.control-grid {
  display: grid;
  gap: 0.65rem;
}

.control-group {
  display: grid;
  gap: 0.3rem;
}

.control-label {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.secondary {
  background: transparent;
  color: var(--accent-2);
  border-color: var(--accent-2);
}

.chip {
  background: transparent;
  color: #244a3a;
  border-color: #8fa996;
}

.chip.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.utility-row {
  padding-top: 0.15rem;
}

.era-groups {
  display: grid;
  gap: 0.8rem;
}

.hidden {
  display: none;
}

.mosaic-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.86);
  box-shadow: var(--shadow);
  padding: 0.9rem;
  margin-bottom: 1rem;
}

.mosaic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 96px);
  justify-content: start;
  gap: 0.35rem;
}

.mosaic-tile {
  position: relative;
  overflow: visible;
  width: 96px;
  height: 96px;
}

.mosaic-thumb {
  width: 96px;
  height: 96px;
  border: 1px solid #cdbda6;
  border-radius: 8px;
  overflow: hidden;
  background: #ece4d5;
  transition: border-color 150ms ease-out, box-shadow 150ms ease-out, transform 150ms ease-out;
}

.mosaic-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.mosaic-tile:hover .mosaic-thumb {
  border-color: #1f6f46;
  box-shadow: 0 0 0 6px rgba(31, 111, 70, 0.58), 0 16px 30px rgba(0, 0, 0, 0.3);
  transform: translateY(-8px) scale(1.055);
  z-index: 3;
}

.mosaic-tooltip {
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px);
  width: 220px;
  max-width: min(220px, 90vw);
  transform: translateY(6px);
  opacity: 0;
  pointer-events: none;
  background: rgba(15, 12, 8, 0.93);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 0.45rem 0.5rem;
  font-size: 0.73rem;
  line-height: 1.3;
  white-space: pre-line;
  z-index: 20;
}

.mosaic-tile:hover .mosaic-tooltip {
  transform: translateY(0);
  opacity: 1;
}

.mosaic-tile.is-hovered .mosaic-thumb {
  border-color: #1f6f46;
  box-shadow: 0 0 0 6px rgba(31, 111, 70, 0.58), 0 16px 30px rgba(0, 0, 0, 0.3);
  transform: translateY(-8px) scale(1.055);
  z-index: 3;
}

.mosaic-tile.is-hovered .mosaic-tooltip {
  transform: translateY(0);
  opacity: 1;
}

.mosaic-tile.is-parent-highlight .mosaic-thumb {
  border-color: #1d59c9;
  box-shadow: 0 0 0 6px rgba(29, 89, 201, 0.62), 0 12px 22px rgba(0, 0, 0, 0.24);
  transform: translateY(-4px) scale(1.035);
  z-index: 2;
}

.map-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
  padding: 0.9rem;
  margin-bottom: 1rem;
  display: grid;
  gap: 0.7rem;
}

.map-section.hidden {
  display: none;
}

.map-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.world-map {
  width: 100%;
  height: min(66vh, 620px);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #cebda4;
  background: #d8e4ed;
}

.map-people-panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  padding: 0.65rem;
  color: var(--muted);
  font-size: 0.9rem;
  min-height: 3rem;
}

.map-people-list {
  display: grid;
  gap: 0.45rem;
}

.map-person-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.map-person-thumb {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid #cdbda6;
  overflow: hidden;
  background: #e9decd;
  flex-shrink: 0;
}

.map-person-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.map-person-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: #5d4a37;
  font-size: 0.68rem;
  font-weight: 700;
}

.map-person-text {
  margin: 0;
  color: var(--ink);
  font-size: 0.86rem;
}

.leaflet-popup-content {
  margin: 0.45rem 0.5rem;
}

.leaflet-popup-content p {
  margin: 0;
  font-size: 0.82rem;
}

details.era {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.86);
  box-shadow: var(--shadow);
}

details.era > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0.9rem;
  font-weight: 600;
}

details.era > summary::-webkit-details-marker {
  display: none;
}

.era-range {
  color: var(--ink);
}

.era-count {
  color: var(--muted);
  font-size: 0.9rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.7rem;
  padding: 0 0.75rem 0.75rem;
}

.person-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem;
  display: grid;
  gap: 0.55rem;
}

.person-header {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid #cdbda6;
  background: #e9decd;
  display: grid;
  place-items: center;
  color: #5d4a37;
  font-weight: 700;
  font-size: 0.8rem;
  overflow: hidden;
  flex-shrink: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.person-name {
  margin: 0;
  font-size: 1rem;
}

.person-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.person-links {
  display: flex;
  gap: 0.6rem;
  color: var(--muted);
  font-size: 0.82rem;
}

@media (max-width: 700px) {
  .container {
    width: calc(100% - 1rem);
    margin-top: 1rem;
  }

  .toolbar {
    top: 0.3rem;
  }

  .control-label {
    font-size: 0.68rem;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .world-map {
    height: min(58vh, 520px);
  }
}
