* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #1a1a2e;
  font-family: Georgia, 'Times New Roman', serif;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

/* Header — year + title */
#header {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  padding: 16px 22px;
  pointer-events: none;
}

#year-display {
  font-size: 2.8rem;
  font-weight: bold;
  color: #c9a96e;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8), 0 0 40px rgba(201, 169, 110, 0.12);
  letter-spacing: 0.04em;
  line-height: 1;
}

#header-sub {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-top: 4px;
}

#title {
  font-size: 0.85rem;
  color: rgba(201, 169, 110, 0.4);
  letter-spacing: 0.25em;
  text-transform: uppercase;
}

#territory-count {
  font-size: 0.7rem;
  color: rgba(201, 169, 110, 0.25);
  letter-spacing: 0.05em;
}

/* Timeline bar — bottom */
#timeline-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(26, 26, 46, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid rgba(201, 169, 110, 0.2);
}

.year-label {
  color: #8a7e6b;
  font-size: 0.85rem;
  white-space: nowrap;
  min-width: 90px;
}

#year-label-max {
  text-align: right;
}

/* Play / speed controls */
#play-btn, #speed-btn {
  background: none;
  border: 1px solid rgba(201, 169, 110, 0.3);
  color: #c9a96e;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

#play-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

#play-btn:hover {
  background: rgba(201, 169, 110, 0.12);
  border-color: rgba(201, 169, 110, 0.5);
}

#play-btn.playing {
  background: rgba(201, 169, 110, 0.15);
  border-color: #c9a96e;
}

#speed-btn {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.75rem;
  padding: 6px 8px;
  letter-spacing: 0.03em;
  min-width: 32px;
}

#speed-btn:hover {
  background: rgba(201, 169, 110, 0.12);
  border-color: rgba(201, 169, 110, 0.5);
}

/* Custom range slider */
#timeline-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: #2d2d44;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

#timeline-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: #c9a96e;
  border-radius: 50%;
  cursor: grab;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 0 6px rgba(201, 169, 110, 0.4);
}

#timeline-slider::-webkit-slider-thumb:hover {
  transform: scale(1.3);
  box-shadow: 0 0 14px rgba(201, 169, 110, 0.6);
}

#timeline-slider::-webkit-slider-thumb:active {
  cursor: grabbing;
}

#timeline-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: #c9a96e;
  border: none;
  border-radius: 50%;
  cursor: grab;
  box-shadow: 0 0 6px rgba(201, 169, 110, 0.4);
}

#timeline-slider::-moz-range-track {
  height: 4px;
  background: #2d2d44;
  border-radius: 2px;
}

/* Loading indicator with spinner */
#loading-indicator {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #c9a96e;
  font-size: 1rem;
  letter-spacing: 0.08em;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  background: rgba(26, 26, 46, 0.8);
  padding: 12px 20px;
  border-radius: 8px;
  border: 1px solid rgba(201, 169, 110, 0.2);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(201, 169, 110, 0.3);
  border-top-color: #c9a96e;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Leaflet tooltip override */
.historical-tooltip {
  background: rgba(26, 26, 46, 0.95) !important;
  color: #d4c5a9 !important;
  border: 1px solid rgba(201, 169, 110, 0.5) !important;
  border-radius: 4px !important;
  font-family: Georgia, 'Times New Roman', serif !important;
  font-size: 0.9rem !important;
  padding: 6px 10px !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5) !important;
}

.historical-tooltip em {
  color: #8a7e6b;
  font-size: 0.82rem;
}

/* Click detail popup */
.historical-popup .leaflet-popup-content-wrapper {
  background: rgba(26, 26, 46, 0.97) !important;
  color: #d4c5a9 !important;
  border: 1px solid rgba(201, 169, 110, 0.4) !important;
  border-radius: 6px !important;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6) !important;
  font-family: Georgia, 'Times New Roman', serif !important;
}

.historical-popup .leaflet-popup-tip {
  background: rgba(26, 26, 46, 0.97) !important;
  border: 1px solid rgba(201, 169, 110, 0.4) !important;
  border-top: none !important;
  border-left: none !important;
}

.historical-popup .leaflet-popup-close-button {
  color: #8a7e6b !important;
  font-size: 1.1rem !important;
}

.historical-popup .leaflet-popup-close-button:hover {
  color: #c9a96e !important;
}

.detail-popup {
  padding: 2px 0;
}

.detail-name {
  font-size: 1.05rem;
  font-weight: bold;
  color: #c9a96e;
  margin-bottom: 8px;
  letter-spacing: 0.03em;
}

.detail-row {
  font-size: 0.82rem;
  color: #b0a48e;
  margin-bottom: 4px;
  line-height: 1.4;
}

.detail-label {
  color: #8a7e6b;
}

/* Map labels — permanent country/region names */
.map-label {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  white-space: nowrap;
  pointer-events: none;
}

.map-label span {
  font-family: Georgia, 'Times New Roman', serif;
  color: rgba(212, 197, 169, 0.75);
  text-shadow:
    0 0 4px rgba(0, 0, 0, 0.9),
    0 0 8px rgba(0, 0, 0, 0.7),
    0 1px 2px rgba(0, 0, 0, 0.8);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  display: block;
  text-align: center;
  transform: translate(-50%, -50%);
}

.map-label-large span {
  font-size: 0.8rem;
  font-weight: bold;
  color: rgba(212, 197, 169, 0.85);
  letter-spacing: 0.2em;
}

.map-label-medium span {
  font-size: 0.65rem;
  font-weight: bold;
  color: rgba(212, 197, 169, 0.7);
}

.map-label-small span {
  font-size: 0.55rem;
  color: rgba(212, 197, 169, 0.55);
}

.map-label-tiny span {
  font-size: 0.48rem;
  color: rgba(212, 197, 169, 0.45);
}

/* Leaflet control overrides for dark theme */
.leaflet-control-zoom a {
  background: rgba(26, 26, 46, 0.9) !important;
  color: #c9a96e !important;
  border-color: rgba(201, 169, 110, 0.2) !important;
}

.leaflet-control-zoom a:hover {
  background: rgba(45, 45, 68, 0.95) !important;
}

.leaflet-control-attribution {
  background: rgba(26, 26, 46, 0.6) !important;
  color: #5a5470 !important;
  font-size: 0.65rem !important;
}

.leaflet-control-attribution a {
  color: #8a7e6b !important;
}

/* Search button — top right, below zoom */
#search-btn {
  position: fixed;
  top: 90px;
  right: 10px;
  z-index: 1000;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 26, 46, 0.9);
  border: 1px solid rgba(201, 169, 110, 0.2);
  border-radius: 4px;
  color: #c9a96e;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s;
}

#search-btn:hover,
#help-btn:hover {
  background: rgba(45, 45, 68, 0.95);
}

#help-btn {
  position: fixed;
  top: 130px;
  right: 10px;
  z-index: 1000;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 26, 46, 0.9);
  border: 1px solid rgba(201, 169, 110, 0.2);
  border-radius: 4px;
  color: #c9a96e;
  cursor: pointer;
  padding: 0;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.9rem;
  font-weight: bold;
  transition: background 0.15s;
}

/* Search overlay */
#search-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(10, 10, 20, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

#search-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

#search-box {
  width: 480px;
  max-width: 90vw;
  background: rgba(26, 26, 46, 0.98);
  border: 1px solid rgba(201, 169, 110, 0.3);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  transform: translateY(-10px);
  transition: transform 0.15s;
}

#search-overlay.open #search-box {
  transform: translateY(0);
}

#search-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(201, 169, 110, 0.15);
  color: #8a7e6b;
}

#search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: #d4c5a9;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1rem;
}

#search-input::placeholder {
  color: rgba(138, 126, 107, 0.6);
}

#search-input-wrap kbd {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.65rem;
  color: #5a5470;
  background: rgba(45, 45, 68, 0.6);
  border: 1px solid rgba(90, 84, 112, 0.3);
  border-radius: 3px;
  padding: 2px 6px;
}

/* Search results */
#search-results {
  max-height: 300px;
  overflow-y: auto;
}

.search-result {
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-result:hover,
.search-result.active {
  background: rgba(201, 169, 110, 0.1);
}

.search-name {
  color: #d4c5a9;
  font-size: 0.9rem;
}

.search-sub {
  color: #8a7e6b;
  font-size: 0.75rem;
}

.search-empty {
  padding: 16px;
  color: #5a5470;
  text-align: center;
  font-size: 0.85rem;
}

/* Scrollbar for search results */
#search-results::-webkit-scrollbar {
  width: 6px;
}

#search-results::-webkit-scrollbar-track {
  background: transparent;
}

#search-results::-webkit-scrollbar-thumb {
  background: rgba(201, 169, 110, 0.2);
  border-radius: 3px;
}

#search-results::-webkit-scrollbar-thumb:hover {
  background: rgba(201, 169, 110, 0.35);
}

/* Legend panel — bottom-left, above timeline */
#legend-panel {
  position: fixed;
  bottom: 60px;
  left: 12px;
  z-index: 1000;
  max-width: 220px;
  background: rgba(26, 26, 46, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(201, 169, 110, 0.2);
  border-radius: 6px;
  overflow: hidden;
  transition: max-height 0.2s ease;
}

#legend-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: none;
  color: #c9a96e;
  cursor: pointer;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#legend-toggle:hover {
  background: rgba(201, 169, 110, 0.08);
}

#legend-chevron {
  margin-left: auto;
  transition: transform 0.2s;
}

#legend-panel.collapsed #legend-chevron {
  transform: rotate(-90deg);
}

#legend-panel.collapsed #legend-list {
  display: none;
}

#legend-list {
  max-height: 240px;
  overflow-y: auto;
  padding: 0 10px 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 0.72rem;
  color: #b0a48e;
  line-height: 1.3;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(201, 169, 110, 0.3);
}

.legend-count {
  color: #5a5470;
  font-size: 0.65rem;
  margin-left: auto;
  white-space: nowrap;
}

/* Legend scrollbar */
#legend-list::-webkit-scrollbar {
  width: 4px;
}

#legend-list::-webkit-scrollbar-track {
  background: transparent;
}

#legend-list::-webkit-scrollbar-thumb {
  background: rgba(201, 169, 110, 0.2);
  border-radius: 2px;
}

/* Wiki panel — slide-out from right */
#wiki-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 100vw;
  z-index: 2000;
  background: rgba(18, 18, 32, 0.98);
  border-left: 1px solid rgba(201, 169, 110, 0.2);
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.5);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

#wiki-panel.open {
  transform: translateX(0);
}

#wiki-close {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 1;
  background: none;
  border: none;
  color: #8a7e6b;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  transition: color 0.15s;
}

#wiki-close:hover {
  color: #c9a96e;
}

#wiki-content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

#wiki-header {
  padding: 28px 28px 20px;
  border-bottom: 1px solid rgba(201, 169, 110, 0.15);
  background: rgba(26, 26, 46, 0.5);
}

#wiki-title {
  font-size: 1.4rem;
  font-weight: bold;
  color: #c9a96e;
  letter-spacing: 0.03em;
  line-height: 1.3;
}

#wiki-subtitle {
  font-size: 0.78rem;
  color: #8a7e6b;
  margin-top: 6px;
  letter-spacing: 0.05em;
}

#wiki-body {
  padding: 24px 28px 40px;
}

/* Wiki section headings */
.wiki-section {
  margin-bottom: 24px;
}

.wiki-section-title {
  font-size: 0.72rem;
  font-weight: bold;
  color: #c9a96e;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(201, 169, 110, 0.12);
}

.wiki-section p {
  font-size: 0.88rem;
  color: #c4b89a;
  line-height: 1.75;
  margin-bottom: 10px;
}

/* Primary source blockquotes — Fischer style */
.wiki-quote {
  margin: 14px 0;
  padding: 12px 18px;
  border-left: 3px solid rgba(201, 169, 110, 0.4);
  background: rgba(201, 169, 110, 0.04);
  border-radius: 0 4px 4px 0;
}

.wiki-quote p {
  font-size: 0.84rem;
  color: #d4c5a9;
  font-style: italic;
  line-height: 1.7;
  margin-bottom: 0;
}

.wiki-quote cite {
  display: block;
  font-size: 0.72rem;
  color: #7a6f5b;
  font-style: normal;
  margin-top: 8px;
  letter-spacing: 0.02em;
}

/* Wiki metadata tags */
.wiki-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.wiki-tag {
  font-size: 0.65rem;
  color: #8a7e6b;
  background: rgba(201, 169, 110, 0.08);
  border: 1px solid rgba(201, 169, 110, 0.15);
  border-radius: 3px;
  padding: 2px 8px;
  letter-spacing: 0.04em;
}

/* Wiki "no entry" placeholder */
.wiki-placeholder {
  text-align: center;
  padding: 40px 20px;
}

.wiki-placeholder-icon {
  font-size: 2.5rem;
  margin-bottom: 16px;
  opacity: 0.3;
}

.wiki-placeholder p {
  color: #5a5470;
  font-size: 0.85rem;
  line-height: 1.6;
}

.wiki-placeholder .wiki-basic-info {
  margin-top: 24px;
  text-align: left;
}

/* Wiki scrollbar */
#wiki-content::-webkit-scrollbar {
  width: 6px;
}

#wiki-content::-webkit-scrollbar-track {
  background: transparent;
}

#wiki-content::-webkit-scrollbar-thumb {
  background: rgba(201, 169, 110, 0.15);
  border-radius: 3px;
}

#wiki-content::-webkit-scrollbar-thumb:hover {
  background: rgba(201, 169, 110, 0.3);
}

/* Mobile responsiveness */
@media (max-width: 600px) {
  #wiki-panel {
    width: 100vw;
  }

  #year-display {
    font-size: 2rem;
  }

  #title {
    font-size: 0.7rem;
  }

  #header {
    padding: 10px 14px;
  }

  #timeline-container {
    padding: 10px 12px;
    gap: 8px;
  }

  .year-label {
    display: none;
  }

  #play-btn {
    width: 32px;
    height: 32px;
  }

  #speed-btn {
    padding: 4px 6px;
    font-size: 0.7rem;
  }

  #legend-panel {
    max-width: 180px;
    bottom: 54px;
  }

  #legend-list {
    max-height: 160px;
  }

  .legend-item {
    font-size: 0.65rem;
  }

  .legend-swatch {
    width: 10px;
    height: 10px;
  }

  #era-label {
    bottom: 50px;
    font-size: 0.6rem;
  }

  #search-box {
    width: 95vw;
    border-radius: 8px;
  }

  #search-btn {
    top: 80px;
  }

  #help-btn {
    top: 120px;
  }

  .map-label-large span {
    font-size: 0.65rem;
  }

  .map-label-medium span {
    font-size: 0.55rem;
  }

  .map-label-small span,
  .map-label-tiny span {
    display: none;
  }
}

/* Keyboard shortcuts overlay */
#shortcuts-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(10, 10, 20, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

#shortcuts-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

#shortcuts-box {
  background: rgba(26, 26, 46, 0.98);
  border: 1px solid rgba(201, 169, 110, 0.3);
  border-radius: 10px;
  padding: 24px 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  min-width: 260px;
}

.shortcuts-title {
  color: #c9a96e;
  font-size: 0.9rem;
  font-weight: bold;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
  text-transform: uppercase;
}

.shortcut-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  color: #b0a48e;
  font-size: 0.82rem;
}

.shortcut-row kbd {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.7rem;
  color: #d4c5a9;
  background: rgba(45, 45, 68, 0.6);
  border: 1px solid rgba(90, 84, 112, 0.4);
  border-radius: 4px;
  padding: 3px 8px;
  min-width: 24px;
  text-align: center;
}

.shortcut-row span {
  margin-left: auto;
  color: #8a7e6b;
}

/* Era label on timeline */
#era-label {
  position: fixed;
  bottom: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  color: rgba(201, 169, 110, 0.5);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.3s;
}
