:root {
  --gm-shadow: 0 1px 2px rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15);
  --gm-shadow-hover: 0 1px 3px rgba(60,64,67,.3), 0 4px 8px 3px rgba(60,64,67,.15);
  --gm-card: #fff;
  --gm-text: #202124;
  --gm-muted: #5f6368;
  --gm-blue: #1a73e8;
  --gm-border: #dadce0;
  --font: "Google Sans", "Noto Sans SC", "PingFang SC", "Microsoft YaHei",
          system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--gm-text);
  background: #aadaff;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.leaflet-container {
  font-family: var(--font);
  background: #aadaff;
}

/* Hide default Leaflet attribution; we have our own strip */
.leaflet-control-attribution { display: none !important; }

/* Zoom control: bottom-right like Google Maps */
.leaflet-bottom.leaflet-right {
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  right: calc(10px + env(safe-area-inset-right, 0px));
}
.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--gm-shadow) !important;
  border-radius: 8px !important;
  overflow: hidden;
}
.leaflet-control-zoom a {
  width: 40px !important;
  height: 40px !important;
  line-height: 40px !important;
  font-size: 20px !important;
  color: var(--gm-muted) !important;
  background: var(--gm-card) !important;
  border: none !important;
  border-bottom: 1px solid var(--gm-border) !important;
}
.leaflet-control-zoom a:last-child { border-bottom: none !important; }
.leaflet-control-zoom a:hover { background: #f8f9fa !important; color: var(--gm-text) !important; }

.gm-card {
  position: absolute;
  z-index: 1000;
  background: var(--gm-card);
  border-radius: 8px;
  box-shadow: var(--gm-shadow);
  color: var(--gm-text);
}

.gm-brand {
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: calc(10px + env(safe-area-inset-left, 0px));
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  min-height: 48px;
  max-width: calc(100vw - 20px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
}

.gm-icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--gm-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.gm-icon-btn:hover { background: #f1f3f4; color: var(--gm-text); }
.gm-icon-btn.is-active { background: #e8f0fe; color: var(--gm-blue); }

.gm-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}
.gm-panel-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--gm-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.gm-panel-close:hover { background: #f1f3f4; color: var(--gm-text); }

.gm-layers {
  top: calc(66px + env(safe-area-inset-top, 0px));
  left: calc(10px + env(safe-area-inset-left, 0px));
  padding: 10px 14px 12px;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.gm-layers[hidden] { display: none !important; }

.gm-events-panel {
  top: calc(66px + env(safe-area-inset-top, 0px));
  left: calc(10px + env(safe-area-inset-left, 0px));
  width: min(320px, calc(100vw - 24px));
  max-height: calc(100vh - 140px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 1050;
}
.gm-events-panel[hidden] { display: none !important; }
.gm-events-sub {
  font-size: 11px;
  color: var(--gm-muted);
  margin: 0 0 2px;
}
.gm-events-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  flex: 1;
  min-height: 0;
}
.gm-events-list li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  padding: 10px 8px;
  border-radius: 8px;
  cursor: pointer;
  border-bottom: 1px solid #f1f3f4;
}
.gm-events-list li:last-child { border-bottom: none; }
.gm-events-list li:hover,
.gm-events-list li:focus-visible {
  background: #f8f9fa;
  outline: none;
}
.gm-events-list li.is-active { background: #e8f0fe; }
.gm-events-list .ev-year {
  grid-row: 1 / 3;
  align-self: start;
  min-width: 4.2em;
  font-size: 11px;
  font-weight: 600;
  color: var(--gm-blue);
  padding-top: 2px;
}
.gm-events-list .ev-title {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--gm-text);
}
.gm-events-list .ev-meta {
  font-size: 11px;
  color: var(--gm-muted);
  line-height: 1.3;
}
.gm-events-empty {
  padding: 16px 8px;
  font-size: 13px;
  color: var(--gm-muted);
  text-align: center;
}
.gm-layers-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--gm-muted);
  text-transform: none;
  letter-spacing: 0.02em;
}
.gm-check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}
.gm-check input { accent-color: var(--gm-blue); width: 16px; height: 16px; margin: 0; }

.gm-year {
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  width: min(560px, calc(100vw - 80px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
}
.gm-year-body { flex: 1; min-width: 0; }
.gm-year-label {
  text-align: center;
  margin-bottom: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.gm-year-input-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#yearInput {
  width: 7.5em;
  max-width: 40vw;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  text-align: center;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--gm-blue);
  padding: 2px 6px;
  outline: none;
}
#yearInput:hover { border-color: var(--gm-border); background: #f8f9fa; }
#yearInput:focus {
  border-color: var(--gm-blue);
  background: #fff;
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.18);
}
.gm-year-snap-hint {
  font-size: 10px;
  font-weight: 400;
  color: var(--gm-muted);
  line-height: 1.2;
}
#yearSlider {
  width: 100%;
  accent-color: var(--gm-blue);
  cursor: pointer;
  margin: 0;
  height: 4px;
}
.gm-year-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--gm-muted);
  margin-top: 2px;
  padding: 0 2px;
  gap: 0;
  overflow: hidden;
}
.gm-year-ticks .tick-major {
  flex: 0 0 auto;
  white-space: nowrap;
  max-width: 3.2em;
  overflow: hidden;
  text-overflow: clip;
}
.gm-year-ticks .tick-gap {
  flex: 1 1 0;
  min-width: 0;
}
.gm-year-step {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--gm-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.gm-year-step:hover { background: #f1f3f4; color: var(--gm-text); }
.gm-year-step:disabled { opacity: 0.35; cursor: default; }

.gm-attrib {
  position: absolute;
  z-index: 900;
  left: 0;
  bottom: 0;
  right: 0;
  padding: 2px 8px;
  padding-bottom: calc(2px + env(safe-area-inset-bottom, 0px));
  font-size: 11px;
  line-height: 1.4;
  color: #444;
  background: rgba(255,255,255,0.85);
  pointer-events: auto;
}
.gm-attrib a { color: #1a73e8; text-decoration: none; }
.gm-attrib a:hover { text-decoration: underline; }
.gm-attrib-btn {
  display: inline;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  color: #1a73e8;
  font: inherit;
  font-size: inherit;
  line-height: inherit;
  cursor: pointer;
  text-decoration: none;
}
.gm-attrib-btn:hover { text-decoration: underline; }

.gm-disclaimer-panel {
  left: calc(8px + env(safe-area-inset-left, 0px));
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  width: min(420px, calc(100vw - 24px));
  max-height: min(70vh, 420px);
  padding: 10px 12px 12px;
  z-index: 1070;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}
.gm-disclaimer-panel[hidden] { display: none !important; }
.gm-disclaimer-body {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--gm-text);
  overflow-y: auto;
  flex: 1 1 auto;
  max-height: min(52vh, 320px);
}
.gm-disclaimer-body p { margin: 0 0 0.65em; }
.gm-disclaimer-body p:last-child { margin-bottom: 0; }
.gm-disclaimer-body strong { font-weight: 600; }

.gm-version {
  position: absolute;
  z-index: 950;
  left: calc(8px + env(safe-area-inset-left, 0px));
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  border: none;
  background: rgba(255, 255, 255, 0.92);
  color: var(--gm-muted);
  font: inherit;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  padding: 5px 8px;
  border-radius: 6px;
  box-shadow: var(--gm-shadow);
  cursor: pointer;
}
.gm-version:hover,
.gm-version[aria-expanded="true"] {
  color: var(--gm-text);
  background: #fff;
}
.gm-version-panel {
  left: calc(8px + env(safe-area-inset-left, 0px));
  bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  width: min(300px, calc(100vw - 24px));
  padding: 10px 12px 12px;
  z-index: 1060;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.gm-version-panel[hidden] { display: none !important; }
.gm-version-tag {
  font-weight: 500;
  color: var(--gm-muted);
  font-variant-numeric: tabular-nums;
}
.gm-version-summary {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--gm-text);
}
.gm-version-highlights {
  margin: 0;
  padding-left: 1.1em;
  font-size: 12px;
  line-height: 1.45;
  color: var(--gm-muted);
}
.gm-version-highlights li { margin: 0.15em 0; }
.gm-version-meta {
  font-size: 11px;
  color: var(--gm-muted);
  line-height: 1.4;
}
.gm-version-link {
  font-size: 11px;
  color: var(--gm-blue);
  text-decoration: none;
  align-self: flex-start;
}
.gm-version-link:hover { text-decoration: underline; }

.leaflet-popup-content-wrapper {
  border-radius: 8px;
  box-shadow: var(--gm-shadow-hover);
  padding: 0;
}
.leaflet-popup-content {
  margin: 10px 12px;
  font-size: 13px;
  line-height: 1.4;
  min-width: 100px;
}
.popup-title { font-weight: 600; font-size: 14px; color: var(--gm-text); }
.popup-meta { font-size: 11px; color: var(--gm-muted); margin-top: 4px; }

@media (max-width: 720px) {
  .gm-brand {
    padding: 4px;
    gap: 0;
  }
  .gm-year {
    width: calc(100vw - 16px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    padding: 10px 8px;
    border-radius: 12px;
  }
  .gm-year-step {
    width: 40px;
    height: 40px;
    font-size: 24px;
  }
  #yearInput { font-size: 14px; width: 8em; }
  .gm-year-ticks { font-size: 8px; }
  .gm-year-ticks .tick-major { max-width: 2.6em; }
  .leaflet-bottom.leaflet-right {
    bottom: calc(108px + env(safe-area-inset-bottom, 0px));
    right: calc(8px + env(safe-area-inset-right, 0px));
  }
  .gm-attrib {
    font-size: 9px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 56px;
  }
  .gm-disclaimer-panel {
    left: calc(8px + env(safe-area-inset-left, 0px));
    right: calc(8px + env(safe-area-inset-right, 0px));
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: min(60vh, 380px);
  }
  .gm-version {
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    font-size: 10px;
    padding: 6px 9px;
  }
  .gm-version-panel {
    bottom: calc(132px + env(safe-area-inset-bottom, 0px));
    left: calc(8px + env(safe-area-inset-left, 0px));
    right: calc(8px + env(safe-area-inset-right, 0px));
    width: auto;
  }

  /* Bottom sheets for overlays on phones */
  .gm-layers,
  .gm-events-panel,
  .gm-sidebar {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    min-width: 0;
    max-height: min(62vh, calc(100vh - 120px));
    border-radius: 16px 16px 0 0;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -2px 12px rgba(60, 64, 67, 0.2);
    z-index: 1200;
  }
  .gm-sidebar {
    max-height: min(70vh, calc(100vh - 100px));
  }
  .gm-events-panel {
    padding-top: 8px;
  }
  .gm-panel-head {
    padding: 4px 2px 6px;
  }
  .gm-events-list li {
    padding: 12px 8px;
    min-height: 44px;
  }
  .gm-check {
    min-height: 40px;
    font-size: 15px;
  }
}

.gm-layers-sub {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--gm-border);
}
.gm-layers {
  max-height: calc(100vh - 120px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  min-width: 200px;
  -webkit-overflow-scrolling: touch;
}
.city-label {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  font-size: 11px;
  font-weight: 600;
  color: #202124;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 1px 1px 2px #fff;
  white-space: nowrap;
}
.city-label::before { display: none !important; }
.capital-dot {
  background: #1a73e8;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
}

/* —— Google Maps–like label hierarchy —— */
.atlas-label-wrap {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}
.atlas-label-wrap::before { display: none !important; }

.label-polity-1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #3c4043;
  text-transform: none;
  text-shadow: 0 0 4px #fff, 0 0 4px #fff, 1px 1px 2px #fff, -1px -1px 2px #fff;
  white-space: nowrap;
  pointer-events: none;
}
.label-polity-2 {
  font-size: 13px;
  font-weight: 650;
  color: #5f6368;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 1px 1px 2px #fff;
  white-space: nowrap;
  pointer-events: none;
}
.label-polity-3 {
  font-size: 12px;
  font-weight: 600;
  color: #80868b;
  text-shadow: 0 0 3px #fff, 1px 1px 2px #fff;
  white-space: nowrap;
  pointer-events: none;
}
.label-province {
  font-size: 11px;
  font-weight: 500;
  font-style: italic;
  color: #5f6368;
  text-shadow: 0 0 3px #fff, 1px 1px 2px #fff;
  white-space: nowrap;
  pointer-events: none;
}
.label-city-capital {
  font-size: 12px;
  font-weight: 600;
  color: #174ea6;
  text-shadow: 0 0 3px #fff, 1px 1px 2px #fff;
  white-space: nowrap;
  pointer-events: none;
}
.label-city-major {
  font-size: 11px;
  font-weight: 550;
  color: #1967d2;
  text-shadow: 0 0 3px #fff, 1px 1px 2px #fff;
  white-space: nowrap;
  pointer-events: none;
}
.label-city {
  font-size: 10px;
  font-weight: 500;
  color: #5f6368;
  text-shadow: 0 0 2px #fff, 1px 1px 1px #fff;
  white-space: nowrap;
  pointer-events: none;
}


.gm-lang-btn {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
}

/* Sidebar (Google Maps–like place card) */
.gm-sidebar {
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: calc(10px + env(safe-area-inset-right, 0px));
  width: min(340px, calc(100vw - 24px));
  max-height: calc(100vh - 120px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px 18px;
  z-index: 1100;
}
.gm-sidebar[hidden] { display: none !important; }
.gm-sidebar-close {
  position: absolute;
  top: 8px; right: 10px;
  border: none; background: transparent;
  font-size: 22px; line-height: 1;
  color: var(--gm-muted); cursor: pointer;
  width: 32px; height: 32px; border-radius: 50%;
}
.gm-sidebar-close:hover { background: #f1f3f4; color: var(--gm-text); }
.gm-sidebar-title {
  margin: 0 28px 4px 0;
  font-size: 18px; font-weight: 600;
}
.gm-sidebar-sub { font-size: 12px; color: var(--gm-muted); margin-bottom: 12px; }
.gm-sidebar-section { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--gm-border); }
.gm-sidebar-h { font-size: 11px; font-weight: 600; color: var(--gm-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.gm-sidebar-bio { font-size: 13px; line-height: 1.45; color: var(--gm-text); white-space: pre-wrap; }
.gm-sidebar-bio .popup-cite { margin-top: 8px; white-space: normal; }
.popup-cite { font-size: 10px; color: #80868b; }

/* Themed event POI markers (category icons) */
.event-poi {
  background: transparent !important;
  border: none !important;
}
.event-poi-inner {
  width: 28px; height: 28px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: grid; place-items: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
  border: 2px solid #fff;
}
.event-poi-inner span {
  transform: rotate(45deg);
  font-size: 13px; line-height: 1;
  color: #fff; font-weight: 700;
}
.event-poi-battle .event-poi-inner { background: #c5221f; }
.event-poi-dynasty .event-poi-inner { background: #9334e6; }
.event-poi-discovery .event-poi-inner { background: #00897b; }
.event-poi-treaty .event-poi-inner { background: #1a73e8; }
.event-poi-religion .event-poi-inner { background: #f9ab00; }
.event-poi-other .event-poi-inner { background: #5f6368; }
.event-poi-imp1 .event-poi-inner { width: 32px; height: 32px; }
.event-poi-imp3 .event-poi-inner { width: 22px; height: 22px; }
.event-poi-imp3 .event-poi-inner span { font-size: 10px; }
