/* Language Families Map */
:root {
  --lm-ocean: #dce9f5;
  --lm-border: rgba(255,255,255,0.5);
  --lm-header-h: 48px;
  --lm-control-h: 44px;
}
html[data-theme="dark"] {
  --lm-ocean: #1a2332;
  --lm-border: rgba(42,42,42,0.5);
}
html[data-theme="reading"] {
  --lm-ocean: #e8dcc8;
  --lm-border: rgba(240,230,212,0.5);
}

body.langmap-body {
  max-width: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.lm-control-bar {
  position: fixed;
  top: var(--lm-header-h);
  left: 0; right: 0;
  height: var(--lm-control-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  z-index: 100;
}

.lm-zoom-toggle {
  display: flex;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--color-border);
}

.lm-zoom-toggle button {
  padding: 6px 14px;
  font-size: 0.82em;
  font-family: var(--font-body);
  font-weight: 600;
  background: var(--color-bg);
  color: var(--color-text-secondary);
  border: none;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.lm-zoom-toggle button.is-active {
  background: var(--color-accent);
  color: #fff;
}

.lm-zoom-toggle button:disabled {
  opacity: 0.4;
  cursor: default;
}

.lm-search-wrap {
  position: relative;
  margin-left: auto;
}

.lm-search-input {
  width: 200px;
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.85em;
  background: var(--color-bg);
  color: var(--color-text);
}

.lm-search-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 0 0 6px 6px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 200;
}

.lm-map-container {
  position: fixed;
  top: calc(var(--lm-header-h) + var(--lm-control-h));
  left: 0; right: 0; bottom: 0;
  background: var(--lm-ocean);
}

.lm-map-container svg {
  width: 100%;
  height: 100%;
}

.lm-polygon {
  stroke: var(--lm-border);
  stroke-width: 0.5;
  cursor: pointer;
  transition: filter 0.2s, opacity 0.3s;
}

.lm-polygon.minor-family {
  stroke-width: 2.5;
  stroke-opacity: 1;
}

.lm-family-label {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  fill: #fff;
  text-anchor: middle;
  pointer-events: none;
  paint-order: stroke;
  stroke: rgba(0,0,0,0.5);
  stroke-width: 3px;
}

.lm-polygon:hover {
  filter: brightness(1.15);
}

.lm-polygon.dimmed {
  opacity: 0.3;
}

.lm-polygon.selected {
  stroke: var(--color-accent);
  stroke-width: 2;
  filter: brightness(1.1);
}

/* Tooltip */
.lm-tooltip {
  position: absolute;
  pointer-events: none;
  background: color-mix(in srgb, var(--color-bg-alt) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 12px 14px;
  max-width: 300px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.15s;
  font-size: 0.88em;
  line-height: 1.5;
}

.lm-tooltip.visible { opacity: 1; }

.lm-tooltip-name {
  font-weight: 700;
  color: var(--color-heading);
  margin-bottom: 2px;
}

.lm-tooltip-native {
  color: var(--color-text-secondary);
  font-style: italic;
}

.lm-tooltip-meta {
  font-size: 0.9em;
  color: var(--color-text-secondary);
  margin: 4px 0;
}

.lm-tooltip-desc {
  color: var(--color-text);
}

/* Detail panel */
.lm-detail-panel {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 380px;
  background: var(--color-bg);
  border-left: 1px solid var(--color-border);
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 150;
  padding: 24px 20px;
}

.lm-detail-panel.is-open {
  transform: translateX(0);
}

.lm-detail-close {
  position: absolute;
  top: 12px; right: 12px;
  background: none;
  border: none;
  font-size: 1.4em;
  cursor: pointer;
  color: var(--color-text-secondary);
  line-height: 1;
}

.lm-detail-name {
  font-size: 1.4em;
  font-weight: 700;
  color: var(--color-heading);
  margin: 0 0 2px;
}

.lm-detail-native {
  font-size: 1em;
  color: var(--color-text-secondary);
  font-style: italic;
  margin: 0 0 12px;
}

.lm-detail-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.lm-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.78em;
  font-weight: 600;
  background: var(--color-bg-alt);
  color: var(--color-text-secondary);
}

.lm-badge.endangered {
  background: #fee;
  color: #c00;
}

.lm-detail-description {
  line-height: 1.7;
  margin-bottom: 16px;
  color: var(--color-text);
}

.lm-detail-history {
  border-left: 3px solid var(--color-accent);
  padding-left: 14px;
  font-size: 0.92em;
  line-height: 1.65;
  color: var(--color-text);
  margin-bottom: 16px;
}

.lm-detail-section-title {
  font-size: 0.82em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--color-text-secondary);
  margin: 20px 0 8px;
}

.lm-related-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.lm-related-item {
  padding: 6px 0;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
}

.lm-related-item:hover {
  color: var(--color-accent);
}

.lm-related-name {
  font-weight: 600;
}

.lm-related-reason {
  font-size: 0.85em;
  color: var(--color-text-secondary);
}

.lm-exit-links {
  list-style: none;
  padding: 0;
  margin: 0;
}

.lm-exit-link {
  display: block;
  padding: 6px 0;
  color: var(--color-accent);
  text-decoration: none;
  font-size: 0.9em;
}

.lm-exit-link:hover { text-decoration: underline; }

/* Legend */
.lm-legend {
  position: absolute;
  bottom: 20px; left: 20px;
  background: color-mix(in srgb, var(--color-bg) 90%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 12px 14px;
  z-index: 100;
  min-width: 180px;
  font-size: 0.85em;
}

.lm-legend.collapsed .lm-legend-entries { display: none; }

.lm-legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-weight: 700;
  color: var(--color-heading);
  margin-bottom: 8px;
}

.lm-legend.collapsed .lm-legend-header { margin-bottom: 0; }

.lm-legend-toggle {
  background: none;
  border: none;
  font-size: 1.1em;
  cursor: pointer;
  color: var(--color-text-secondary);
}

.lm-legend-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  cursor: pointer;
  border-radius: 4px;
}

.lm-legend-entry:hover { background: var(--color-bg-alt); }

.lm-legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

.lm-legend-name { flex: 1; }

.lm-legend-count {
  color: var(--color-text-secondary);
  font-size: 0.85em;
}

/* First-visit overlay */
.lm-first-visit {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.lm-first-visit[hidden] {
  display: none;
}

.lm-first-visit-card {
  background: var(--color-bg);
  border-radius: 12px;
  padding: 36px 32px;
  max-width: 440px;
  text-align: center;
  box-shadow: 0 16px 48px rgba(0,0,0,0.2);
}

.lm-first-visit-card h2 {
  margin: 0 0 12px;
  color: var(--color-heading);
}

.lm-first-visit-card p {
  line-height: 1.7;
  color: var(--color-text);
  margin: 0 0 20px;
}

.lm-first-visit-btn {
  padding: 10px 28px;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
}

/* Responsive */
@media (max-width: 1023px) {
  .lm-detail-panel {
    width: 320px;
  }
}

@media (max-width: 767px) {
  .lm-control-bar {
    padding: 0 10px;
    gap: 8px;
  }
  .lm-zoom-toggle button {
    padding: 6px 10px;
    font-size: 0.78em;
  }
  .lm-search-wrap { display: none; }
  .lm-detail-panel {
    width: 100%;
    left: 0; right: 0;
    border-left: none;
    border-top: 1px solid var(--color-border);
  }
  .lm-legend {
    bottom: 10px; left: 10px;
    max-width: calc(100% - 20px);
  }
}
