/* Trade Routes Map — Styles */

:root {
  --map-land: #e8e0d0;
  --map-water: #b8d4e8;
  --map-coastline: #999;
  --map-route-color: #c0392b;
  --map-route-maritime: #2980b9;
  --map-node-fill: #f39c12;
  --map-node-stroke: #fff;
  --site-header-h: 48px;
}

html[data-theme="dark"] {
  --map-land: #2a2a2a;
  --map-water: #1a2332;
  --map-coastline: #555;
  --map-route-color: #e74c3c;
  --map-route-maritime: #3498db;
  --map-node-fill: #f1c40f;
  --map-node-stroke: #333;
}

html[data-theme="reading"] {
  --map-land: #ddd4c0;
  --map-water: #c8bfae;
  --map-coastline: #a09080;
  --map-route-color: #a0503a;
  --map-route-maritime: #4a7a9b;
  --map-node-fill: #c8a040;
  --map-node-stroke: #f0e6d4;
}

/* ── Page layout ──────────────────────────────────────────────────── */

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

.trade-map-page {
  width: 100vw;
  height: calc(100vh - var(--site-header-h));
  margin-top: var(--site-header-h);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ── Canvas ───────────────────────────────────────────────────────── */

.map-canvas {
  flex: 1;
  background: var(--map-water);
  position: relative;
  overflow: hidden;
}

.map-canvas svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Land & coastline ────────────────────────────────────────────── */

.land {
  fill: var(--map-land);
}

.coastline {
  stroke: var(--map-coastline);
  stroke-width: 0.5;
  fill: none;
}

/* ── Routes ───────────────────────────────────────────────────────── */

.route {
  stroke: var(--map-route-color);
  stroke-width: 2.5;
  fill: none;
  opacity: 0.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 200ms ease, stroke-width 200ms ease;
}

.route.maritime {
  stroke: var(--map-route-maritime);
  stroke-dasharray: 8 4;
}

.route:hover {
  opacity: 1;
  stroke-width: 3.5;
}

/* ── Nodes ────────────────────────────────────────────────────────── */

.node {
  cursor: pointer;
}

.node circle {
  fill: var(--map-node-fill);
  stroke: var(--map-node-stroke);
  stroke-width: 1.5;
  transition: transform 200ms ease, stroke 200ms ease, stroke-width 200ms ease;
}

.node.major circle {
  r: 8;
}

.node:not(.major) circle {
  r: 5;
}

.node:hover circle {
  transform: scale(1.3);
}

.node.selected circle {
  stroke: var(--color-accent, #2563eb);
  stroke-width: 3;
}

.node-label {
  font-family: var(--font-body, 'Manrope', 'Segoe UI', sans-serif);
  font-size: 10px;
  font-weight: 600;
  fill: var(--color-text, #1a1a2e);
  pointer-events: none;
  text-anchor: start;
  dominant-baseline: central;
  opacity: 0;
  transition: opacity 200ms ease;
}

.node.major .node-label {
  opacity: 1;
}

/* Show all labels on zoom > 3 (controlled by JS adding class) */
.map-canvas.zoomed-in .node-label {
  opacity: 1;
}

/* ── Tooltip ──────────────────────────────────────────────────────── */

.map-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--color-bg-alt, #f8fafc);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 8px;
  padding: 10px 14px;
  max-width: 300px;
  z-index: 200;
  opacity: 0;
  transition: opacity 150ms ease;
  font-size: 0.85rem;
  line-height: 1.5;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

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

.map-tooltip-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--color-heading, #0f172a);
  margin-bottom: 2px;
}

.map-tooltip-local {
  font-size: 0.8rem;
  color: var(--color-text-secondary, #475569);
  margin-bottom: 4px;
}

.map-tooltip-summary {
  color: var(--color-text, #1a1a2e);
  font-size: 0.82rem;
  line-height: 1.45;
}

/* ── Detail panel ────────────────────────────────────────────────── */

.map-detail-panel {
  position: absolute;
  right: 0;
  top: 0;
  width: 380px;
  height: 100%;
  overflow-y: auto;
  background: var(--color-bg, #ffffff);
  border-left: 1px solid var(--color-border, #e2e8f0);
  box-shadow: -4px 0 16px rgba(0,0,0,0.08);
  transform: translateX(100%);
  transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 150;
  padding: 24px 20px;
}

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

.detail-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--color-bg-alt, #f8fafc);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: var(--color-text-secondary, #475569);
  transition: background 150ms ease, color 150ms ease;
  z-index: 10;
}

.detail-close-btn:hover {
  background: var(--color-border, #e2e8f0);
  color: var(--color-text, #1a1a2e);
}

.detail-heading {
  font-family: var(--font-heading, 'Sora', sans-serif);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--color-heading, #0f172a);
  margin-bottom: 2px;
  padding-right: 40px;
}

.detail-local-name {
  font-size: 0.9rem;
  color: var(--color-text-secondary, #475569);
  margin-bottom: 8px;
}

.detail-period {
  font-family: var(--font-heading, 'Sora', sans-serif);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-accent, #2563eb);
  margin-bottom: 16px;
}

.detail-section-title {
  font-family: var(--font-heading, 'Sora', sans-serif);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary, #475569);
  margin-top: 20px;
  margin-bottom: 8px;
}

.detail-summary {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--color-text, #1a1a2e);
  margin-bottom: 4px;
}

/* ── Empires timeline ────────────────────────────────────────────── */

.empires-timeline {
  position: relative;
  height: 28px;
  margin: 8px 0 4px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--color-bg-alt, #f8fafc);
  border: 1px solid var(--color-border, #e2e8f0);
}

.empire-segment {
  position: absolute;
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 600;
  color: #fff;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 0 4px;
  border-right: 1px solid rgba(255,255,255,0.3);
  cursor: default;
  transition: filter 200ms ease;
}

.empire-segment:hover {
  filter: brightness(1.15);
}

.empire-dates {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--color-text-secondary, #475569);
  margin-top: 2px;
}

/* ── Trade goods pills ───────────────────────────────────────────── */

.trade-goods-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.trade-good-pill {
  display: inline-block;
  background: var(--color-bg-alt, #f8fafc);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-text, #1a1a2e);
  white-space: nowrap;
}

/* ── Links ────────────────────────────────────────────────────────── */

.detail-links {
  margin-top: 4px;
}

.link-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 0.82rem;
  color: var(--color-accent, #2563eb);
  text-decoration: none;
  cursor: pointer;
  transition: color 150ms ease;
}

.link-item:hover {
  color: var(--color-heading, #0f172a);
  text-decoration: underline;
}

.link-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  opacity: 0.7;
}

/* ── Legend ────────────────────────────────────────────────────────── */

.map-legend {
  position: absolute;
  bottom: 20px;
  left: 20px;
  background: var(--color-bg, #ffffff);
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--color-border, #e2e8f0);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  z-index: 50;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  font-size: 0.78rem;
}

.legend-title {
  font-family: var(--font-heading, 'Sora', sans-serif);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary, #475569);
  margin-bottom: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  color: var(--color-text, #1a1a2e);
}

.legend-line {
  width: 24px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}

.legend-line.overland {
  background: var(--map-route-color);
}

.legend-line.maritime {
  background: var(--map-route-maritime);
  background-image: repeating-linear-gradient(
    90deg,
    var(--map-route-maritime) 0px,
    var(--map-route-maritime) 6px,
    transparent 6px,
    transparent 10px
  );
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--map-node-fill);
  border: 1.5px solid var(--map-node-stroke);
  flex-shrink: 0;
}

.legend-dot.minor {
  width: 7px;
  height: 7px;
}

/* ── Search (hidden Tier 1) ──────────────────────────────────────── */

.map-search-wrap {
  display: none;
}

/* ── Slider (hidden Tier 1) ──────────────────────────────────────── */

.map-time-slider-wrap {
  display: none;
}

/* ── Responsive: tablet (768-1023px) ─────────────────────────────── */

@media (max-width: 1023px) {
  .map-detail-panel {
    width: 320px;
  }

  .map-legend {
    bottom: 12px;
    left: 12px;
    padding: 10px 12px;
  }
}

/* ── Responsive: mobile (320-767px) ──────────────────────────────── */

@media (max-width: 767px) {
  .map-detail-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--color-border, #e2e8f0);
    top: auto;
    bottom: 0;
    height: 60%;
    transform: translateY(100%);
    border-radius: 16px 16px 0 0;
  }

  .map-detail-panel.open {
    transform: translateY(0);
  }

  .map-legend {
    bottom: 8px;
    left: 8px;
    padding: 8px 10px;
    font-size: 0.72rem;
  }

  .map-tooltip {
    max-width: 240px;
    font-size: 0.8rem;
  }

  .detail-heading {
    font-size: 1.1rem;
  }
}
